Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Find Question

  1. #1
    Guest

    Default

    How do I select the entire row of all items in a column that begin with the letter "SP"
    in VBA

    Thanks

    Mauro

  2. #2
    MrExcel MVP Tom Urtis's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, California USA
    Posts
    11,162
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Assuming your column is A, then try this macro, keeping in mind that the SP is case sensitive, as you presented it in your post.

    This does what you ask, which is select the whole row when the value in column A starts with SP.

    Thanks to my friend Celia (a former ME regular) for the code syntax inspiration.


    Sub SelectSP()
    Dim theCol As Range, cell As Range, RtoSel As Range
    Dim LtoSel As String
    Set theCol = Range(Range("A1"), Range("A65536").End(xlUp))
    LtoSel = "SP"
    For Each cell In theCol
    If Left(cell, 2) = LtoSel Then
    If RtoSel Is Nothing Then
    Set RtoSel = cell
    Else
    Set RtoSel = Application.Union(RtoSel, cell)
    End If
    End If
    Next
    On Error GoTo e
    RtoSel.EntireRow.Select
    Exit Sub
    e:
    MsgBox "There is nothing to select.", vbInformation, "How about that!"
    End Sub


    HTH

    Tom Urtis

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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