View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Why does this code not work?

Just a note about your first suggestion:

1. wks = "sheet" & Trim(Str(n))

The Str function actually introduces that space character.
wks = "Sheet" & n
would would nicely--it wouldn't include any spaces.



wrote:

On 4 sep, 10:06, rk0909 wrote:
All,

I am trying to use the code name of sheets instead of the tab name, but it
wouldn't work for me. Any help will be appreciated.

Thanks much,

RK

Sub test()
Dim n As Integer

n = 1
wks = "sheet" & n

wks.Select
End Sub


Hi Rk:

You need to do some changes:

1. wks = "sheet" & Trim(Str(n))
This, becuase the n variable is numeric (integer) and the string
representation has a space at left. You should remove the space.

2. Worksheets(wks).Select
The reason is that wks is a string variable, not an object. You pass
the sheet name (the value of wks variable) to the Worksheets
collection.


--

Dave Peterson