Try this code, Rick. It first hides all columns, then unhides column E (5) if the checkbox is checked:
Private Sub Submit_Click()
Columns().Hidden = True
If CheckBox1.Value = True Then
Columns(5).Hidden = False
End If
Unload UserForm1
End Sub
-Ben
I am not using a "user form". The check boxes are in sheet1 and the columns I am hiding are on sheet2. By the way there are multiple check boxes on sheet1 for the user to select. Would the same principle work and just keep writing the same code but substitute check1 for 2 for 3 etc...
Once the user has selected all the columns they need and hit submit then sheet2 is revealed only showing the needed(selected) columns.
Rick,
Yes, you can use the repeat the same code for each column, just changing the number for each one. Your code could be something like this:
If CheckBox1.Value = True Then
Sheets(2).Columns(1).Hidden = False
End If
I tried to make a For To look using CheckBox(x), but that didn't work.
-Ben
As soon as the code find a "false" checkbox it ends if.
I have 6 checkboxes.
Lets say
check1= true
check2=false
check3=true
check4=true
check5= false
check6=true
The code will only "unhide" the column associated with check1..... it ignores check3,check4 and check6.....
I had some trouble getting to to work too. Then I realized I didn't change all of the numbers I had to change. Finally, I was able to fix whatever problems there were. See if this code works for you. It works for me.
Private Sub CommandButton1_Click()
If CheckBox1.Value = True Then
Sheets(2).Columns("A").Hidden = False
End If
If CheckBox2.Value = True Then
Sheets(2).Columns("B").Hidden = False
End If
If CheckBox3.Value = True Then
Sheets(2).Columns("C").Hidden = False
End If
If CheckBox4.Value = True Then
Sheets(2).Columns("D").Hidden = False
End If
If CheckBox5.Value = True Then
Sheets(2).Columns("E").Hidden = False
End If
If CheckBox6.Value = True Then
Sheets(2).Columns("F").Hidden = False
End If
End Sub
-Ben
Private Sub CommandButton1_Click() Sheets(2).Columns("A").Hidden = False If CheckBox2.Value = True Then Sheets(2).Columns("B").Hidden = False If CheckBox3.Value = True Then Sheets(2).Columns("C").Hidden = False If CheckBox4.Value = True Then Sheets(2).Columns("D").Hidden = False If CheckBox5.Value = True Then Sheets(2).Columns("E").Hidden = False If CheckBox6.Value = True Then Sheets(2).Columns("F").Hidden = False End Sub