Excel VBA: Input Box returning "SN Found" or "SN Not Found"

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

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:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top