Array error

  • Thread starter Thread starter pwz
  • Start date Start date
P

pwz

Hello All,

I have encountered the following error message:

Run-time error '9'
Subscript out of range

sName1 = sh.Name & " Hi"
sName2 = sh.Name & " Hello"
Sheets(Array(sName1, sName2)).Copy

The copy statement works if I replace the variables with actual sheet name.
May anyone give some hints to me? Thanks in advance!


Regards,

PW
 
pwz said:
Hello All,

I have encountered the following error message:

Run-time error '9'
Subscript out of range

sName1 = sh.Name & " Hi"
sName2 = sh.Name & " Hello"
Sheets(Array(sName1, sName2)).Copy

The copy statement works if I replace the variables with actual sheet name.
May anyone give some hints to me? Thanks in advance!


Regards,

PW
What is sh?

Alan Beban
 
Dear Alan,

Sorry that 'sh' is also a variable of worksheet. I finally figure out the
solution. I need to use another variable to capture the name of the
worksheet and use this new variable to concantenate with other text to form
new worksheet names. Then, the array formula in copy statement works.

The problem now is that I don't know the reason behind.

Anyway, thanks to you!

PW
 
Back
Top