Consulting

Results 1 to 4 of 4

Thread: Convert String to Range

  1. #1

    Question Convert String to Range

    Hello ppl,

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

    [vba]
    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

    [/vba]
    thanks in advance!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This works for me

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Since Cells(a,b).Row = a, why not use this

    [VBA]strRange = strRange & lngRow & ":" & lngRow[/VBA]

    or [VBA]strRange = strRange & Sheets(gsrtfilename).Rows(lngRow).Address(False,False)[/VBA]

  4. #4
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    Quote Originally Posted by mikerickson
    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.
    [vba]

    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


    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •