View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Script works in forms element but doesn't in normal option button

Sheets("Voorbeeldportefeuille").Select
*Columns("H:K").Select*


You need to qualify Columns("H:K") with the sheet reference. Normally
without the reference the activesheet is implied, but as your code is in a
worksheet module the code tries to select those columns in its own sheet.
But it can't because it's no longer active. Instead try

Sheets("Voorbeeldportefeuille").Columns("H:K").Sel ect

Actually you really don't need to select, simply

Sheets("Voorbeeldportefeuille").Columns("H:K").Ent ireColumn.Hidden = False

(you don't even need to activate the sheet to do the above)

Regards,
Peter T


If the worksheet module with your code does not "Voorbeeldportefeuille" you
will need t
"CalamityJane" wrote in message
...
Hello,

I'm programming a Macro to hide/unhide some entire rows and colums, but
the
following proble occurs:

When I add the following script to the option button from controls, it
displays an error in line 3 (in the example marked with *):

Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
Sheets("Voorbeeldportefeuille").Select
*Columns("H:K").Select*
Selection.EntireColumn.Hidden = False
Else
Sheets("Invoer").Select
End If
End Sub

When I use the option button from the Forms toolbar, I get the following
script after recording the macro, and it works perfectly:

Sub Keuzerondje25_BijKlikken() (- = Sub
Optionbutton25_Click())
Sheets("Voorbeeldportefeuille").Select
Columns("H:K").Select
Selection.EntireColumn.Hidden = False
End Sub

Great that it works, but I want to use the option button from the controls
toolbar, as I need to use the change function, in stead of the click
function. Can anyone tell me what I'm doing wrong?

Thanks.