stuartchaffey
New Member
- Joined
- Dec 28, 2021
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hi, i hope someone can help. i have the below code that keeps debugging at "newRow = APPLICATION.Match(commCell.Value, newColumnA, 0)", this was working last night but has since stopped, any help appreciated.
'COPIES DATA FROM THE RETURNED SHEET AND PLACES DATA INTO NEW SHEET
Sub MatchAndCopyData()
Dim commWs As Worksheet
Dim newWs As Worksheet
Dim commColumnA As Range
Dim newColumnA As Range
Dim commRow As Long
Dim newRow As Long
' Set references to the relevant sheets
Set commWs = ThisWorkbook.Sheets("Communication")
Set newWs = ThisWorkbook.Sheets("New")
' Set references to the columns
Set commColumnA = commWs.Range("A:A")
Set newColumnA = newWs.Range("A:A")
' Loop through each cell in commColumnA
For Each commCell In commColumnA
If Not IsEmpty(commCell.Value) Then
' Find the matching row in newColumnA
On Error Resume Next
newRow = APPLICATION.Match(commCell.Value, newColumnA, 0)
On Error GoTo 0
If Not IsError(newRow) Then
' Copy data from columns F, G, H, I, J, & K
commWs.Cells(commCell.Row, "F").Resize(1, 6).Copy _
Destination:=newWs.Cells(newRow, "F")
End If
End Sub
'COPIES DATA FROM THE RETURNED SHEET AND PLACES DATA INTO NEW SHEET
Sub MatchAndCopyData()
Dim commWs As Worksheet
Dim newWs As Worksheet
Dim commColumnA As Range
Dim newColumnA As Range
Dim commRow As Long
Dim newRow As Long
' Set references to the relevant sheets
Set commWs = ThisWorkbook.Sheets("Communication")
Set newWs = ThisWorkbook.Sheets("New")
' Set references to the columns
Set commColumnA = commWs.Range("A:A")
Set newColumnA = newWs.Range("A:A")
' Loop through each cell in commColumnA
For Each commCell In commColumnA
If Not IsEmpty(commCell.Value) Then
' Find the matching row in newColumnA
On Error Resume Next
newRow = APPLICATION.Match(commCell.Value, newColumnA, 0)
On Error GoTo 0
If Not IsError(newRow) Then
' Copy data from columns F, G, H, I, J, & K
commWs.Cells(commCell.Row, "F").Resize(1, 6).Copy _
Destination:=newWs.Cells(newRow, "F")
End If
End Sub