Hi guys,
I desperately need help on my code that should simply be hiding some columns. I cant get it to work and I dont understand where i go wrong.
The code I have now looks like this:
What it should do is actually quite simple. Whenever in row 2 the value of the cell is equal to cell I11 in the Command sheet it should hide the row. The reason i am working with cases is that the same code would also have to work for different values in row 2 refereing to different cells in the command sheet. However i am sure that when i get the first case to work the others would be easy.
For now the code doesnt work other than that it loops through all the sheets. I have the feeling that it is testing the value only in the command sheet but i dont know how to change the code...
Thanks for your help on this.
Robbert
I desperately need help on my code that should simply be hiding some columns. I cant get it to work and I dont understand where i go wrong.
The code I have now looks like this:
Code:
Private Sub CommandButton1_Click()
Dim Choice As String
'determine which button is checked?
If Me.OptionButton1.Value = True Then Choice = 1
If Me.OptionButton2.Value = True Then Choice = 2
If Me.OptionButton3.Value = True Then Choice = 3
'process the option button
Select Case Choice
Case Is = 1
Dim Cell As Range
Dim ws As Worksheet
Dim c As Long
For Each ws In ThisWorkbook.Worksheets
ws.Activate
c = 10
For Each Cell In ws.Range("F2:AK2")
Cell.EntireColumn.Hidden = IIf(Cells(2, c).Value = Sheets("Command").Range("$I$11").Value, True, False)
c = c + 1
Next Cell
Next ws
Case Is = 2
' do something
Case Is = 3
' do something
End Select
End Sub
What it should do is actually quite simple. Whenever in row 2 the value of the cell is equal to cell I11 in the Command sheet it should hide the row. The reason i am working with cases is that the same code would also have to work for different values in row 2 refereing to different cells in the command sheet. However i am sure that when i get the first case to work the others would be easy.
For now the code doesnt work other than that it loops through all the sheets. I have the feeling that it is testing the value only in the command sheet but i dont know how to change the code...
Thanks for your help on this.
Robbert