Consulting

Results 1 to 3 of 3

Thread: Solved: Highlight entire row when item is found.

  1. #1
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location

    Solved: Highlight entire row when item is found.

    Hello people ,

    I'm trying to write a macro which will find something a user inputs
    into an Inputbox. Then highlights the entire row.
    So far I have this:

    [VBA]

    Sub FindThenHighlightWholeRow()
    '
    ' Prompts for input, finds it, then highlights whole row.
    '

    Dim toFind

    toFind = Application.InputBox("What to search for:")

    If toFind <> "" Then
    Cells.Find(What:=toFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False).Activate
    ActiveCell.EntireRow.Activate
    End If

    End Sub[/VBA]

    Although it highlights the found cell it doesn't highlight
    the whole row.

    I'm most likley missing something simple...

    Thanks ,

    Marcster.

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    [vba]Sub FindThenHighlightWholeRow()
    '
    ' Prompts for input, finds it, then highlights whole row.
    '

    Dim toFind

    toFind = Application.InputBox("What to search for:")

    If toFind <> "" Then
    Cells.Find(What:=toFind, After:=ActiveCell, LookIn:=xlValues, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False).EntireRow.Activate
    End If

    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    If toFind <> "" Then
    Cells.Find(What:=toFind, After:=ActiveCell, LookIn:=xlValues, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False).EntireRow.Activate
    End If
    The last bit .EntireRow.Activate is what I was missing.

    Thanks,

    Marcster.

Posting Permissions

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