vendredi 20 novembre 2020

Add new formatted row with checkbox linked to next cell

I am relatively new to VBA and learning as I go. I am trying to make a form in Excel that allows me to copy the formatting from the previous row to create a new row, and also create a checkbox in Column C and links it to the same row but in Column A. I have executed the code for both of these and they work great, but I cannot figure out how to get them to run together. Creating a macro to call both macros at the same time resulted in error. Anyone have any ideas? I will include the code I have working now.

For adding a new row with formatting based on the row above it:

Sub InsertRow()

ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1).EntireRow.PasteSpecial xlPasteFormats
Application.CutCopyMode = False

End Sub

For adding a checkbox to a specific column and linking it to Column A:

Sub addCheckbox() Dim c As Range

Selection.Offset(1, 0).Select

For Each c In Selection
    Dim cb As CheckBox
    Set cb = ActiveSheet.CheckBoxes.Add(c.Left, _
                                c.Top, _
                                c.Width, _
                                c.Height)
    With cb
        .Caption = ""
        .Value = xlOff
        .LinkedCell = c.Offset(0, -2).Address
        .Display3DShading = False
    End With
Next

End Sub

Thanks!




Aucun commentaire:

Enregistrer un commentaire