Use userform checkbox to select columns

Jimmypop

Well-known Member
Joined
Sep 12, 2013
Messages
753
Office Version
  1. 365
Platform
  1. Windows
Good day again

I have a Userform with 12 Checkboxes on it. I am struggling to get it right with this project. I have done this on a previous project where if value of checkbox is true then it will select a row.

So my issue now, and I don't know what I am doing wrong, is that on Userform when I select Checkbox 1 then it will select the column that I want... However when I select Checkbox 1 and let's say Checkbox 7 then it will only select the column range linked to Checkbox 7 and not Checkbox 1 and 7... I need the end user to select whatever checkbox/s they want and then it needs to select those columns together with "A1:A39". So basically if they select Checkbox1 then it needs to select "A1:A39" together with "B1:B39"... If they select Checkbox1 and Checkbox7 then it needs to select "A1:A39" together with "B1:B39" and "H1:H39" etc...

Here is the code I am using...

VBA Code:
Private Sub GenerateData_Click()

Range("A1:A39").Select

If Me.Checkbox1.Value = True Then
  Range("B1:B39").Select
End If

If Me.Checkbox2.Value = True Then
  Range("C1:C39").Select
End If

If Me.Checkbox3.Value = True Then
  Range("D1:D39").Select
End If

If Me.Checkbox4.Value = True Then
  Range("E1:E39").Select
End If

If Me.Checkbox5.Value = True Then
  Range("F1:F39").Select
End If

If Me.Checkbox6.Value = True Then
  Range("G1:G39").Select
End If

If Me.Checkbox7.Value = True Then
  Range("H1:H39").Select
End If

If Me.Checkbox8.Value = True Then
  Range("I1:I39").Select
End If

If Me.Checkbox9.Value = True Then
  Range("J1:J39").Select
End If

If Me.Checkbox10.Value = True Then
  Range("K1:K39").Select
End If

If Me.Checkbox11.Value = True Then
  Range("L1:L39").Select
End If

If Me.Checkbox12.Value = True Then
  Range("M1:M39").Select
End If

End Sub
 
Glad you figured it out & thanks for the feedback
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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