JaimeMabini
New Member
- Joined
- Dec 29, 2021
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
Hello VBA Guru's!
I am fairly new to VBA. I have here a VBA code that compares attributes from sheet1 to sheet2. if attributes in sheet1 column A is found in sheet2 column A, copy the entire row in sheet1 and paste/replace that row in sheet2.
What I need now in addition to this code. is an exit statement. I need the VBA job to end and exit automatically when it reaches row 3421 or it can dynamically change depending on the input of the end user in sheet1.
Thank you and any help will be highly appreciated.
Best Regards.
I am fairly new to VBA. I have here a VBA code that compares attributes from sheet1 to sheet2. if attributes in sheet1 column A is found in sheet2 column A, copy the entire row in sheet1 and paste/replace that row in sheet2.
VBA Code:
Sub UpdateSheet2()
Dim i As Long
Dim f As Range, c As Range
Application.ScreenUpdating = False
With Sheets("Sheet2")
For Each c In .Range("A1", .Range("A" & Rows.Count).End(3))
Set f = Sheets("Sheet1").Range("A:A").Find(c.Value, , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
f.EntireRow.Copy
.Range("A" & c.Row).PasteSpecial xlValues
End If
Next
End With
Application.CutCopyMode = False
End Sub
What I need now in addition to this code. is an exit statement. I need the VBA job to end and exit automatically when it reaches row 3421 or it can dynamically change depending on the input of the end user in sheet1.
Thank you and any help will be highly appreciated.
Best Regards.