VBA searching for a specific value using imputbox

miisstina

New Member
Joined
Sep 27, 2014
Messages
10
Hi all,

I have just started learning Vba.

I am trying to create search for a value using an input box which goes through a range and determines the first value that exceeds the value chosen via input box. I have absolutely no idea where to begin. (Also I hope I make sense)

Any help to steer me in the correct direction would be greatly appreciated
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
try something like this

Code:
Sub test()
Dim cfind As Range, x, c As Range
Worksheets("sheet1").Activate
x = InputBox("type the number you want as input e.g. 2")
x = CLng(x)
Set cfind = Columns("a:a").Cells.Find(what:=x, lookat:=xlWhole)
'MsgBox cfind.Address
For Each c In Range(cfind.Offset(1, 0), cfind.End(xlDown))
MsgBox c.Address
If c.Value > x Then
MsgBox c.Address
Exit Sub
End If
Next c








End Sub
 

miisstina

New Member
Joined
Sep 27, 2014
Messages
10
try something like this

Code:
Sub test()
Dim cfind As Range, x, c As Range
Worksheets("sheet1").Activate
x = InputBox("type the number you want as input e.g. 2")
x = CLng(x)
Set cfind = Columns("a:a").Cells.Find(what:=x, lookat:=xlWhole)
'MsgBox cfind.Address
For Each c In Range(cfind.Offset(1, 0), cfind.End(xlDown))
MsgBox c.Address
If c.Value > x Then
MsgBox c.Address
Exit Sub
End If



Next c








End Sub
Thank you very much!
 

Watch MrExcel Video

Forum statistics

Threads
1,113,903
Messages
5,544,962
Members
410,643
Latest member
sng
Top