PDA

View Full Version : Convert String to Range



WillyTheFish
10-26-2008, 06:04 AM
Hello ppl,

any idea how i convert a string to a range? I won't get this to work:


Dim strRange As String

'...later on in the function:
strRange = strRange & Sheets(gstrFilename).Cells(lngRow, bytCol).Row & ":" & Sheets(gstrFilename).Cells(lngRow, bytCol).Row & ":"

Range(Left(strRange, Len(strRange) - 1)).Select


thanks in advance!

Bob Phillips
10-26-2008, 06:14 AM
This works for me



Dim strRange As String

'...later on in the function:
With Sheets(gstrFilename)

strRange = strRange & .Cells(lngRow, bytCol).Row & ":" & .Cells(lngRow, bytCol).Row
End With

Range(strRange).Select

mikerickson
10-26-2008, 12:37 PM
Since Cells(a,b).Row = a, why not use this

strRange = strRange & lngRow & ":" & lngRow

or strRange = strRange & Sheets(gsrtfilename).Rows(lngRow).Address(False,False)

david000
10-26-2008, 12:45 PM
Since Cells(a,b).Row = a, why not use this

I noticed that too, but I didn't see your post. I went with a square range anyhow.

Also, try using the Address property.


Sub CellAddress()

Dim strRange As String

'...later on in the function:
With Sheets("Sheet1")
strRange = .Name & "!" & .Cells(1, "A").Address & ":" & .Cells(100, "M").Address
End With

Range(strRange).Select

End Sub