Solved

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

Posted on 2015-01-12
2
155 Views
Last Modified: 2015-01-21
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
0
Comment
Question by:cowboywm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40546030
Hi,

pls try

    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

Open in new window

Regards
0
 

Author Closing Comment

by:cowboywm
ID: 40562758
This solution works great!  Thank you, Rgonzo1971.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A list of useful business intelligence software.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question