Check Boxes And Macro HELP

  • Thread starter Thread starter Johnathon
  • Start date Start date
J

Johnathon

hi,
i have a spreadsheet with about 4 columns of data. while
recording a macro i deleted every cell in the 4 columns
of data. i then had a button and i assined this new macro
to the button. basically the button just cleared all the
data.

But, i need to give the user a choice as to which columns
they want deleted. so i thought i could use a checkbox
for each column and they would then select whichever
checkboxes / columns they wanted deleted.

But i cannot work out how to go about this problem. i
have tried recording macros that just select the cells
and then assigned them to the checkboxes. but when the
user clicks two checkboxes it does not select the two
columns.

can anyone help. any ideas would be welcome.
thanks
 
i have a spreadsheet with about 4 columns of data. while
recording a macro i deleted every cell in the 4 columns
of data. i then had a button and i assined this new macro
to the button. basically the button just cleared all the
data.

But, i need to give the user a choice as to which columns
they want deleted. so i thought i could use a checkbox
for each column and they would then select whichever
checkboxes / columns they wanted deleted.

But i cannot work out how to go about this problem. i
have tried recording macros that just select the cells
and then assigned them to the checkboxes. but when the
user clicks two checkboxes it does not select the two
columns.

can anyone help. any ideas would be welcome.
thanks

OK, add your check boxes to the sheet you want and then use the code below.
In my example below I've used just 4 check boxes, if you want anymore then
just increase the if statements inside the msgbox loop appropriately. My
check boxes are all named cbColA, cbColB, cbColC and cbColD just continue
the scheme.

Hope this helps.

Chris

Private Sub CommandButton1_Click()

x = MsgBox("Do you want to clear the columns", vbOKCancel + vbQuestion,
"Clear Contents")
If x = 1 Then
If cbColA.Value = True Then
Range("A:A").ClearContents
End If

If cbColB.Value = True Then
Range("B:B").ClearContents
End If

If cbColC.Value = True Then
Range("C:C").ClearContents
End If

If cbColD.Value = True Then
Range("D:D").ClearContents
End If
End If

End Sub
 
Back
Top