简体   繁体   中英

Indirect reference to range in other sheet using VBA

In Sheet1 of my Excel file I have the following input:

           A              B    
1   'Sheet2'!J:O      
2

In Cell A1 is the range that should be hidden in Sheet2 when I run this VBA:

Sub Hiding_Columns()
Sheet1.Range(Range("A1")).EntireColumn.Hidden = True
End Sub

However, with this code I get runtime error 1004.

What do I need to change to make it work?

Perhaps the following:

Range(Sheet1.Range("A1").Value).EntireColumn.Hidden = True

The way you have it is (when Sheet1 is the active sheet) equivalent to:

Sheet1.Range("'Sheet2'!J:O").EntireColumn.Hidden = True

and that won't work because you've got the sheets mixed together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM