userform checkbox to determine which portion of code to run

baker_89

New Member
Joined
Aug 25, 2014
Messages
42
I have a userform with 6 checkboxs, all, mon, tue, wed, thur, fri, sat. I want the user to be able to pick which date(sheet) to choose to run certain code on. This is what I have but it doesn't work right.

Private Sub CommandButton1_Click()




If all.Value = True Then
Clear Ranges in all sheets
Else

If mon.Value = True Then
'Clear Ranges on Sheets 1 & 2

If tue.Value = True Then
'Clear Ranges on Sheets 3 & 4
Else

If thur.Value = True Then
'Clear Ranges on Sheets 5 & 6
Else

If fri.Value = True Then
'Clear Ranges on Sheets 7 & 8
Else

If sat.Value = True Then
'Clear Ranges on Sheets 1 & 2
Else

End If

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Mike. I saw the ' marks and do understand they are normally used for comments.
The first command:
If all.Value = True Then
Clear Ranges in all sheets
Else
has no ' at the beginning of the line.
So if none of this is code then what is the purpose of all this?


When I put in "Clear Ranges in Sheets 1 & 2" I was subbing for my code that clears ranges so it didn't make the post longer than needed. The code I had in place was,

Sheets("Sheet1").Range("B3:B34,E3:F34,R9:T18").ClearContents
Sheets("Sheet2").Range("G3:H34,M3:N34").ClearContents
 
Upvote 0
Ok Thanks at first I thought "what" I never knew this trick.
When I put in "Clear Ranges in Sheets 1 & 2" I was subbing for my code that clears ranges so it didn't make the post longer than needed. The code I had in place was,

Sheets("Sheet1").Range("B3:B34,E3:F34,R9:T18").ClearContents
Sheets("Sheet2").Range("G3:H34,M3:N34").ClearContents
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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