I have been following this forum for some time but this is my first post. I am hoping that the wisdom out there can point me in the right direction to fix this problem. I have scoured the internet to no avail.
I have been compiling a workbook with many formulas, named ranges and several macros. This macro (below) has worked correctly a couple of times (step through) but usually starts to loop through the user defined functions and adds a number or rows incorrectly. I have deleted all the macros and named ranges that are not used and checked all the formulas. I am at a loss what else to do and any advice would be greatly appreciated.
Sub CopyPick()
Dim InputRngCount As Long
Dim PredictRngCount As Long
Dim InputRng As Range
Dim a As Long
Dim b As Long
Dim StartRow As Integer
Dim HoleID As String
Dim Match1 As Variant
Dim pck_import As ListObject
Dim Predict_Rec As ListObject
On Error GoTo ErrHandler
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set InputRng = ActiveWorkbook.Worksheets("Recoveries Predicts").ListObjects("pck_import").DataBodyRange
PredictRngCount = ActiveWorkbook.Sheets("Recoveries Predicts").ListObjects("Predict_Recovery_Tbl").DataBodyRange.Rows.Count
InputRngCount = ActiveWorkbook.Sheets("Recoveries Predicts").ListObjects("pck_import").DataBodyRange.Rows.Count + 3 '+3 to count worksheet row number
HoleID = ActiveWorkbook.Sheets("Recoveries Predicts").Range("AP4")
Set pck_import = ActiveWorkbook.Worksheets("Recoveries Predicts").ListObjects("pck_import")
Set Predict_Rec = ActiveWorkbook.Sheets("Recoveries Predicts").ListObjects("Predict_Recovery_Tbl")
StartRow = ActiveWorkbook.Sheets("Recoveries Predicts").Range("C:C").Find(What:=HoleID, After:=ActiveWorkbook.Sheets("Recoveries Predicts").Range("C3"), LookIn:=xlValues).row
For a = StartRow To InputRngCount
For b = 4 To InputRngCount
If Cells(b, 45).Value <> Cells(a, 7).Value Then
Match1 = Application.Match(Cells(a, 7).Value, Range("pck_import[Seam]"), 0)
If Not IsError(Match1) Then
Predict_Rec.ListRows.Add (a - 3)
InputRngCount = InputRngCount + 1
Else
pck_import.ListRows.Add (b - 3)
Predict_Rec.ListRows.Add (a - 2)
InputRngCount = InputRngCount + 2
End If
End If
a = a + 1
Next b
Next a
MsgBox "Data has been copied"
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
ErrHandler:
MsgBox "Hole ID does not exist"
Exit Sub
End Sub
Bookmarks