Hi,
I have a macro that is able to find differences between two columns that are side by side and then spits out the differences onto another sheet. The macro works well when there are differences, but if the two columns are the same, then I get a 400 error. What do I need to do so that my code essentially has an "iferror" built it or so that if there are no differences between the columns, I can have a pop up that says "No new plan and program names" instead of getting an error? Thank you!
Dim LastRow As Long
Dim LastRowB As Long
Application.ScreenUpdating = False
Set ws1 = Sheets("Plan and Program Assign Metrics")
Set ws2 = Sheets("Plan and Program Database")
Set ws3 = Sheets("Plan and Program Pivot Table")
ws3.Visible = xlSheetVisible
ws2.Visible = xlSheetVisible
ws3.PivotTables("ProgramTable").PivotCache.Refresh
LastRowB = Cells(Rows.Count, "B").End(xlUp).Row
LastRow = Cells(Rows.Count, "A").End(xlUp).Offset(-1).Row
Application.CutCopyMode = False
ws3.Range("B6:B" & LastRowB).Clear
ws2.Range("A3:A" & LastRow).Copy
ws3.Range("B6").PasteSpecial Paste:=xlPasteValues
ar = Range("a6").CurrentRegion 'Change input to suit
ReDim var(1 To UBound(ar, 1), 1 To 1)
With CreateObject("scripting.dictionary")
.comparemode = 1
For i = 1 To UBound(ar, 1)
.Item(ar(i, 2)) = Empty
Next
For i = 1 To UBound(ar, 1)
If Not .exists(ar(i, 1)) Then
n = n + 1
var(n, 1) = ar(i, 1)
End If
Next
End With
ws1.[A4].Resize.Value = var 'Change output to suit
ws3.Visible = xlSheetHidden
ws2.Visible = xlSheetHidden
ws1.Activate
Application.ScreenUpdating = True
MsgBox "Raw Data Refreshed and New Plans and Programs Listed"
End Sub
I have a macro that is able to find differences between two columns that are side by side and then spits out the differences onto another sheet. The macro works well when there are differences, but if the two columns are the same, then I get a 400 error. What do I need to do so that my code essentially has an "iferror" built it or so that if there are no differences between the columns, I can have a pop up that says "No new plan and program names" instead of getting an error? Thank you!
Dim LastRow As Long
Dim LastRowB As Long
Application.ScreenUpdating = False
Set ws1 = Sheets("Plan and Program Assign Metrics")
Set ws2 = Sheets("Plan and Program Database")
Set ws3 = Sheets("Plan and Program Pivot Table")
ws3.Visible = xlSheetVisible
ws2.Visible = xlSheetVisible
ws3.PivotTables("ProgramTable").PivotCache.Refresh
LastRowB = Cells(Rows.Count, "B").End(xlUp).Row
LastRow = Cells(Rows.Count, "A").End(xlUp).Offset(-1).Row
Application.CutCopyMode = False
ws3.Range("B6:B" & LastRowB).Clear
ws2.Range("A3:A" & LastRow).Copy
ws3.Range("B6").PasteSpecial Paste:=xlPasteValues
ar = Range("a6").CurrentRegion 'Change input to suit
ReDim var(1 To UBound(ar, 1), 1 To 1)
With CreateObject("scripting.dictionary")
.comparemode = 1
For i = 1 To UBound(ar, 1)
.Item(ar(i, 2)) = Empty
Next
For i = 1 To UBound(ar, 1)
If Not .exists(ar(i, 1)) Then
n = n + 1
var(n, 1) = ar(i, 1)
End If
Next
End With
ws1.[A4].Resize.Value = var 'Change output to suit
ws3.Visible = xlSheetHidden
ws2.Visible = xlSheetHidden
ws1.Activate
Application.ScreenUpdating = True
MsgBox "Raw Data Refreshed and New Plans and Programs Listed"
End Sub