Fine

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a macro, with a in put box for a number and find the number in column
A .
bring number to the top of sheet.


Thanks , need need help

Donald E
PS E-mail me with the code
 
This is untested, but should work, if the number is in column A.

Sub fndNbr()
lr = Cells(Rows.Count, 1).End(xlUp).Row
srchNbr = InputBox("Enter a number", "Number")
With ActiveSheet.Range("A2:A" & lr)
Set c = .Find(srchNbr, LookIn:xlValues)
If Not c Is Nothing Then
Range("A1") = c
End If
End With
End Sub
 
Hi donald,

I prepared and answer and I now see someone else has answered. However, I'll
post my code anyway because it is a variation on the other answer. This code
cuts the number from the original location and inserts it at the top. It also
allows you to continue your searches until you click cancel.

Sub Macro1()
Dim inputNumber As Variant
Dim foundCell As Range

Do
inputNumber = InputBox("Enter the number to be found" & _
Chr(13) & "Cancel to exit")

With Sheets("Sheet1").Columns("A")
Set foundCell = .Find(What:=inputNumber, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If foundCell.Value <> "" Then
foundCell.Cut
.Cells(1, 1).Insert Shift:=xlDown
End If
End With
Loop While inputNumber <> ""

End Sub

Regards,

OssieMac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top