I have put together the following VBA to delete rows on a worksheet (there's another VBA for adding rows, not shown here). I want to be able to delete the row contents, together with the associated checkboxes in that row, and move all rows up to fill the space. For info, G4 = value of row to be deleted, B4 = the total number of filled rows, F4 = G4+1. The first code works perfectly, deleting the row, moving everything up and updating the cell contents. The second code (Delete_Checkboxes_in_Row) is a small subroutine to delete the checkboxes in that row - unfortunately this does not do anything. Can anyone help? I've modified it several times, but still come up with the same problem.
Code:
Sub Delete_Row()
'
' To delete a defined row but retain all formatting and formula interdependencies in all other rows
'
Worksheets("R-O PS").Activate
Dim myValue As Variant
myValue = InputBox("Insert Line Number to Delete", "Delete Line")
Worksheets("R-O PS").Range("G4").Value = myValue
If Worksheets("R-O PS").Range("G4").Value = 0 Then
MsgBox "Insert Line Number"
Exit Sub
End If
Call Delete_Checkboxes_in_Row
Application.ScreenUpdating = False
Dim s1 As String
Dim s2 As String
s1 = Worksheets("R-O PS").Range("B4")
s2 = Worksheets("R-O PS").Range("F4")
With Worksheets("R-O PS").Range(s2 & ":" & s1).Select
Selection.Copy
Selection.Offset(-1, 0).PasteSpecial xlPasteAll
End With
Worksheets("R-O PS").Range("G4").ClearContents
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Code:
Sub Delete_Checkboxes_in_Row()
Dim c As CheckBox
For Each c In Worksheets("R-O PS").CheckBoxes
If Not Intersect(c.TopLeftCell, Worksheets("R-O PS").Range("G4")) Is Nothing Then
c.Delete
End If
Next
End Sub