View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Die_Another_Day Die_Another_Day is offline
external usenet poster
 
Posts: 644
Default How do I select a sheet

Check what strDataName is set to. There are many ways to select a sheet
1. Create a Sheet object and reference that
Dim nSheet as Worksheet
Set nSheet = Sheets("Sheet1")
nSheet.Activate
2. Activate By Name
Sheets("Sheets1").Activate
3. Activate By Index
Sheets(1).Activate
4.Declare String Variable, Activate by that (your current mode)
Dim strDataName as String
strDataName = "Sheet1"
Sheets(strDataName).Activate

there are probably others but that should get you close enough
HTH

Die_Another_Day
Ben H wrote:
Hi all

I have a macro that uses this line of code. I recorded it and this is what
it gave me
Sheets(strDataName).Select
So i saved the sheet then went to lunch and came back to get this error
message.
"run-time error 1004 - select method of worksheet class failed"

Anyone know why this would work before but not after lunch?
Is there a different way to select a worksheet?

Thanks - Ben H.