Value of the worksheet index

  • Thread starter Thread starter Cliff
  • Start date Start date
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
 
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
 
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
 
Back
Top