jeudi 15 juin 2017

VBA: Code to link checkboxes to a button as well as rows within a table

I have a button that I'd like to link to checkboxes within a table that when clicked will clear their corresponding rows and shift the rest of the table up. How do I run a loop/link the checkboxes to their corresponding rows in order to make the following code more efficient?

Sub CommandButton1_Click()
If CheckBox1.Value = True Then
Range("B6:O6").Clear
Range("B7:O42").Select
Range("B7:O42").Cut Destination:=Range("B6:O42")
Range("B6:O41").Select
End If

CheckBox1.Value = False

If CheckBox2.Value = True Then
Range("B7:O7").Clear
Range("B8:O42").Select
Range("B8:O42").Cut Destination:=Range("B7:O42")
Range("B7:O41").Select
End If
CheckBox2.Value = False




Aucun commentaire:

Enregistrer un commentaire