+ Reply to Thread
Results 1 to 3 of 3

Chunks of Macro being skipped when running

Hybrid View

  1. #1
    Registered User
    Join Date
    01-25-2012
    Location
    Berkeley, Ca
    MS-Off Ver
    Excel 2007
    Posts
    13

    Chunks of Macro being skipped when running

    I have a macro to insert formulas based on specific cell values. The macro run on several sheets.. The second sheet works perfectly and the first sheet works perfectly when ran to a breakpoint. When the macro is run in its entirety the first sheets does not work. If I move the variables it will work once but not again. Any advice would be appreciated.

    Sub NewTest()
    Dim Response As Integer
    Dim LR As Long: LR = Cells(Rows.Count, 17).End(xlUp).Row
    Dim i As Long
    Dim BR As Long: BR = Cells(Rows.Count, 21).End(xlUp).Row
    Dim z As Long
    Application.ScreenUpdating = False
    
    ' Displays a message box with the yes and no options.
    Response = MsgBox(prompt:="Have You Updated Report Pages with Player Numbers?", Buttons:=vbYesNo)
    
    ' If statement to check if the yes button was selected.
    If Response = vbYes Then
    
    'select Weight Report Sheet
    Sheets("Ind-Report (Wt)").Select
    
    'Add Look up Formulas below last months test
    For i = LR To 3 Step -1
        If Not (IsEmpty(Cells(i, 17))) Then
            Cells(i, 1).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,2,)"
            Cells(i, 2).Select
            Selection.Formula = "='Recording Sheet WTs'!$e$1"
            Cells(i, 3).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,3,)"
            Cells(i, 5).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,8,)"
            Cells(i, 6).Select
            Selection.Formula = "=iferror((e" & i & ")/(c" & i & "),"""")"
            Cells(i, 7).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,5,)"
            Cells(i, 8).Select
            Selection.Formula = "=iferror(((g" & i & ")*2.2)/(c" & i & "),"""")"
            Cells(i, 9).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,11,)"
            Cells(i, 10).Select
            Selection.Formula = "=iferror((i" & i & ")/(c" & i & "),"""")"
            Cells(i, 11).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,12,)"
            Cells(i, 12).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,13,)"
            Cells(i, 13).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,4,)"
            Cells(i, 15).Select
            Selection.Formula = "=vlookup(q" & i & ",'Recording Sheet WTs'!$A$5:$N$39,14,)"
        
        End If
        
    Next i
    
    'Select Field report Sheet
    Sheets("Ind-Report (Field)").Select
    
    'Add look up formulas below last months test
    For z = BR To 3 Step -1
        If Not (IsEmpty(Cells(z, 21))) Then
            Cells(z, 1).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,2,)"
            Cells(z, 2).Select
            Selection.Formula = "='Recording Sheet Cond'!$e$1"
            Cells(z, 3).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,3,)"
            Cells(z, 5).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,4,)"
            Cells(z, 7).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,5,)"
            Cells(z, 9).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,6,)"
            Cells(z, 11).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,7,)"
            Cells(z, 13).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,8,)"
            Cells(z, 15).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Cond'!$A$5:$N$39,9,)"
            Cells(z, 17).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Shuttle'!$A$5:$T$39,15,)"
            Cells(z, 19).Select
            Selection.Formula = "=vlookup(u" & z & ",'Recording Sheet Shuttle'!$A$5:$T$39,16,)"
        End If
        
        Next z
        
    'Clear Last Test Recording forms
    Sheets("Recording Sheet WTs").Select
    Range("C5:G39").Select
    Selection.ClearContents
    Range("I5:J39").Select
    Selection.ClearContents
    Range("L5:N39").Select
    Selection.ClearContents
    
    
    Sheets("Recording Sheet Cond").Select
    Range("C5:I39").Select
    Selection.ClearContents
    
    Sheets("Recording Sheet Shuttle").Select
    Range("C5:J39").Select
    Selection.ClearContents
    
    Else
    
    ' The no button was selected.
    MsgBox "Update Reports then re-click New Test Button"
    End If
        
        
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: Chunks of Macro being skipped when running

    The answers will come from a little skill with debugging code.

    Here are a few tips.

    1. Use break points to temporarily stop the process and check to see if it has done what you expected that section to do.
    2. On errors, use the debug option. Inspect the variables to see what does not look right.

  3. #3
    Registered User
    Join Date
    01-25-2012
    Location
    Berkeley, Ca
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Chunks of Macro being skipped when running

    Dennis - Thanks for the reply. This is were I'm stuck. When I toggle breakpoints to run each part on their own. It works great. When I run the entire macro, I don't get an error message it just does not execute the macro on one of the sheets. It almost as if I could put in a breakpoint permanently in the macro it would work but would be to much of a pain to have as 2 different macros.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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