Getting a compile error with a very simple VBA code

borski88

Board Regular
Joined
Jul 3, 2015
Messages
71
I have this simple code open a hidden sheet:

Code:
Sub Test()
    
    Sheets("sheet1").Visible = True
    Sheets("sheet1").Select

End Sub

I get the following Compile Error:
Compile Error:
Wrong number of arguments or invalid property assignments
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Where are you putting the code.....there is no reason that it shouldn't work !
IS the sheet hidden or VeryHidden ?
 
Upvote 0
Yeah, Michael is right. There's no reason why it shouldn't work, whether hidden or very hidden. When the error occurs, which text gets highlighted?
 
Upvote 0
It's not clear what is being highlighted in your example.

This works fine for me and as others above, seem unable to replicate your error:
Code:
Sub Test()


    With Sheets("Sheet1")
        .Visible = True
        .Select
    End With


End Sub
Maybe a typo in the sheet name you're using? Have you tried running the same code in a different (new) workbook?
 
Upvote 0
Try this:

Code:
Sub Test()
    
With Application.Sheets("Sheet1")
    .Visible = True
    .Select
End With


End Sub
 
Upvote 0
Actually I have a question... are you simply trying to run this code by itself, or are you calling it from somewhere else? If you step through your code does it work?
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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