Link to home
Start Free TrialLog in
Avatar of William C Johnson
William C JohnsonFlag for United States of America

asked on

How to use an input box variable in an Excel search function

How can you combine a variable with Excel 2007 Search function?  I do not want the user to run the search directly so I want to search built by what he/she enters into an input box.   Below is a sample sheet and macro.

                       Column A
Row1            TAR NBR
Row2            1
Row3            2
Row4            3
Row 5            4
Row 6            5
Row 7            6
Row 8            7
Row 9            8
Row 10              9
Row 11            10
Row 12            11

  Range("A1").Select
    Dim MyValue As Integer
    Dim TARNbr As Integer
    Prompt = "Search for which TAR?"
    Caption = "Tell me..."
    TARNbr = InputBox(Prompt, Caption, MyValue)
    Cells.Find(What:="TARNbr", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        True, SearchFormat:=False).Activate
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of William C Johnson

ASKER

This solution works great!  Thank you, Rgonzo1971.