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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,589
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Where are you putting the code.....there is no reason that it shouldn't work !
IS the sheet hidden or VeryHidden ?
 
Upvote 0

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,895
Office Version
  1. 365
Platform
  1. Windows
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

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,900
Office Version
  1. 365
Platform
  1. Windows
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

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,504
Office Version
  1. 365
Platform
  1. Windows
Try this:

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


End Sub
 
Upvote 0

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,504
Office Version
  1. 365
Platform
  1. Windows
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,190,878
Messages
5,983,366
Members
439,841
Latest member
goodwillhunting

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
Top