Bluesguy07
New Member
- Joined
- Mar 11, 2016
- Messages
- 28
Hello Guys and Gals,
I found this macro elsewhere, and modified it slightly to fit my needs. However, I'm unsure how to turn it essentially into an IF statement where it returns "SN Found" if it does find the serial number or "SN Not Found" if it does not find the serial number. I would also like to add something that will actually copy the serial number if found into column C (starting with C2) and if not found into column D (D2). Any assistance would be greatly appreciated.
*Note* - This is a 1 page workbook, so multiple worksheets are not needed for this
Just as an aside, I am not even sure that all of the code I referenced is needed for this task.
I found this macro elsewhere, and modified it slightly to fit my needs. However, I'm unsure how to turn it essentially into an IF statement where it returns "SN Found" if it does find the serial number or "SN Not Found" if it does not find the serial number. I would also like to add something that will actually copy the serial number if found into column C (starting with C2) and if not found into column D (D2). Any assistance would be greatly appreciated.
*Note* - This is a 1 page workbook, so multiple worksheets are not needed for this
Code:
Sub SNLookup()Dim x As Long
Dim lr, lookRng As Range
Dim findStr As String
Dim foundCell As Variant
lr = Cells(Rows.Count, "A").End(xlUp).Row
Set lookRng = Range("A1:A" & lr)
findStr = InputBox("Enter Serial Number")
For x = 1 To lr
If Range("A" & x).Value = findStr Then
Set foundCell = Range("A" & x).Offset(0, 1)
MsgBox foundCell & "SN Found"
End If
Next x
End Sub
Just as an aside, I am not even sure that all of the code I referenced is needed for this task.
Last edited: