Value of the worksheet index

C

Cliff

I have had errors using variables to refer to ranges in a worksheet, specifically within FOR loops.
What types of variables are the indx and rnge as described in the reference below...

Worksheets(indx).range(rnge)

I have been using either variants (which should work for any type??) and integer and string
respectively however I get type mismatch errors with those last types.

Thanks,

Cliff
 
F

Frank Kabel

Hi Cliff
you may post your complete code :)
but using an index nnumber (defined as integer) for worksheets and a
string with a valid reference for a range should work.

Sub foo()
Dim indx As Long
Dim rnge As String
indx = 1
rnge = "A1"
Worksheets(indx).Select
Range(rnge).Select
End Sub
 
B

Bob Phillips

indx is Long, rnge is a string. Integer will work fine, and String is fine.
Post the code and tell us the error.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Cliff said:
I have had errors using variables to refer to ranges in a worksheet, specifically within FOR loops.
What types of variables are the indx and rnge as described in the reference below...

Worksheets(indx).range(rnge)

I have been using either variants (which should work for any type??) and integer and string
respectively however I get type mismatch errors with those last types.

Thanks,
Cliff
 

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

Top