VBA to delete checkboxes in a row

ninja_jim

New Member
Joined
Apr 30, 2018
Messages
1
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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try changing this:

Intersect(c.TopLeftCell, Worksheets("R-O PS").Range("G4"))

to this:

Intersect(c.TopLeftCell, Worksheets("R-O PS").Rows(Range("G4").Value))
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top