question

TirrellEric-4069 avatar image
0 Votes"
TirrellEric-4069 asked

VBA to Copy Specifc Rows if Matching Criteria is Met

Hey All,

I am very new to VBA and I'm working on Macro and can't seem to make it work. I am trying to write one to copy Rows DB:DJ and EM:EX on sheet 1 to rows AM:BG on Sheet 2 as long as Column L in sheet 1 matches Column M in sheet 2. What I have so far is below:

 Sub ABC()
 Dim s1 As Worksheet, s2 As Worksheet
 Set s1 = Sheets("Sheet1")
 Set s2 = Sheets("Sheet2")
 Dim ir As Long, ir2 As Long
 Dim i As Long
 ir = s1.Range("L" & Rows.Count).End(xlUp).Row
 Application.ScreenUpdating = False
 For i = 2 To ir
 ir2 = s2.Range("M" & Rows.Count).End(xlUp).Row
 If s1.Range("L" & i) = s2.Range("M" & i) Then
 s1.Range("L" & "DB11:DJ102" & "EM12:EX102").RowsCount.Copy
 s2.Range("M" & "AM2:BG88").PasteSpecial xlPasteValues
 End If
 Next i
 Applications.CutCopyMode = False
 Applications.ScreenUpdating = True
 MsgBox "Complete"
    
 End Sub

Please let me know if you need additional information. Any help is much appreciated!


office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers