How to copy one row from the specific found cell from one sheet to another

mahshadrashidpour

New Member
Joined
Jul 17, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a list of serial numbers and MMID and Batch number of each serial number .
and I want to build a tool that when one serial number is scanned, the MMID and Batch number are printed on the label.
I have written this code but it doesn't work correctly.



Dim i As Integer

For i = 1 To 2


Dim a
Dim Rng As Range
Dim lr As Long


a = InputBox("Please scan the serial number") 'Inserting serial Number

If Trim(a) <> "" Then
With Sheets("MMIDs").Range("A:A") 'searches the serial number all of column A
Set Rng = .Find(What:=a, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True 'value found
lr = Sheets("Result").Cells(Rows.Count, "A").End(xlUp).Row + 1 'Find first blank row on new sheet
Application.EnableEvents = False
Sheets("MMIDs").Cells(i, "A").EntireRow.Copy Destination:=Sheets("Result").Range("A" & Rows.Count).End(xlUp).Offset(1)

Else
MsgBox "Serial Number Not found" 'value not found
End If
End With
End If

Next i

End Sub
SerialMMIDBatch Number
PHWL724401GL160MGN927199TWPH76P215
PHWL7244017U160MGN927199TWPH76P215
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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