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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top