Results 1 to 9 of 9

Macro problem - loops theough user defined functions not called in macro

Threaded View

  1. #1
    Registered User
    Join Date
    01-18-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro problem - loops theough user defined functions not called in macro

    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
    Last edited by beccyclaire; 01-24-2016 at 09:50 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] User-defined type not defined on Copy to Clipboard Macro
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2015, 11:31 AM
  2. User Defined function getting called for all the formula calculation cells
    By 1man in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2014, 08:36 AM
  3. user defined macro to replace certain characters in a string based on user input
    By whatappears in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2012, 06:25 PM
  4. Problem with loops/recorded macro
    By yookd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-10-2010, 06:39 PM
  5. Replies: 2
    Last Post: 05-11-2006, 11:35 AM
  6. Using user defined workbook name in macro worksheet functions
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-06-2005, 02:06 PM
  7. [SOLVED] How to: User Form to assign a user defined range to a macro variab
    By TrevTrav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1