help.. want write a simple marco

D

dickychan

l want write a simple marco to auto find a number in a long range o
number...like the following:
. A B
1 1 59
2 77 90
3 99 103
4 111 145
5 150 170
6 187 200

the value in A and B is mean from A to B.....like row 1..it mean
1, 2, 3, up to 59....and so on of other rows....
what l want is have a inputbox for me to input a value like
155....
and l need find in row 1's (A1: B1) ....then row'2 A and B ..until en
of row...
if the number what l input is in the those range...then msgbox show m
have this number....
Pls help...........th
 
B

Bernie Deitrick

dickychan,

Try something like this, assuming your data starts in cell A1, and there is
nothing else in column A besides your table.

Sub FindNumberRow()
Dim myNum As Integer
myNum = Application.InputBox("What number?")
If myNum >= Application.Min(Range("A:B")) And _
myNum <= Application.Max(Range("A:B")) Then
MsgBox "It's in row " & Application.Match( _
myNum, Range("A:A"))
Else
MsgBox "You picked a number out of my range!"
End If
End Sub

HTH,
Bernie
MS Excel MVP
 
Top