VBA looping in excel 2010

kthorson16

New Member
Joined
Sep 3, 2015
Messages
27
Looking for assistance with my current VBA Macro in excel 2010 that is to perform the following function.

Based on what is located in column I on tab "Covers" it will got to the correct macro, once it runs the needed macro I am wanting it to loop thru to the next row/cell in column "I" until it gets to a cell in column "I" that is blank. I am fairly new to the VBA macro writing world and am at a loss.

Can anyone provide some assistance?

Sub main_macro()
If Range("I7").Value = "A" Then
Call A_Macro
ElseIf Range("I7").Value = "B" Then
Call B_macro
ElseIf Range("I7").Value = "C" Then
Call C_macro
ElseIf Range("I7").Value = "D" Then
Call D_macro
Else
Return
End If

End Sub
Sub A_Macro()

Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim Location As String
Dim rDirList As String

Application.ScreenUpdating = False
wdMonth = Sheets("Cover").Range("F7").Value
wdPath = Sheets("Cover").Range("G7").Value
OWFP = Sheets("Cover").Range("F7").Value
Details = Sheets("Cover").Range("H7").Value
TWB = ThisWorkbook.Name
Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))

For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows(wdMonth).Activate
Sheets(Details).Select

ActiveSheet.Range("f802:aq803").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next

End Sub

Sub B_macro()
Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
wdMonth = Sheets("Cover").Range("F7").Value
wdPath = Sheets("Cover").Range("G7").Value
OWFP = Sheets("Cover").Range("F7").Value
Details = Sheets("Cover").Range("H7").Value
TWB = ThisWorkbook.Name
Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))

For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows(wdMonth).Activate
Sheets(Details).Select

ActiveSheet.Range("f803:aq805").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next
End Sub

Sub C_macro()
Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
wdMonth = Sheets("Cover").Range("F7").Value
wdPath = Sheets("Cover").Range("G7").Value
OWFP = Sheets("Cover").Range("F7").Value
Details = Sheets("Cover").Range("H7").Value
TWB = ThisWorkbook.Name
Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))

For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows(wdMonth).Activate
Sheets(Details).Select

ActiveSheet.Range("f804:aq806").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next
End Sub
Sub D_macro()
Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
wdMonth = Sheets("Cover").Range("F7").Value
wdPath = Sheets("Cover").Range("G7").Value
OWFP = Sheets("Cover").Range("F7").Value
Details = Sheets("Cover").Range("H7").Value
TWB = ThisWorkbook.Name
Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))

For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows(wdMonth).Activate
Sheets(Details).Select

ActiveSheet.Range("f1004:aq1006").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select

Next
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I am wanting it to loop thru to the next row/cell in column "I" until it gets to a cell in column "I" that is blank.
Here is one way of doing that:
Code:
    Dim myLastRow As Long
    Dim cell As Range
    
'   Find last row before first blank in column I
    myLastRow = Range("I1").End(xlDown).Row
    
'   Loop through all cells in column I until the first blank
    For Each cell In Range("I1:I" & myLastRow)
[I]        'Your code here[/I]
    Next cell
 
Upvote 0
It is not looping thru, have I added this incorrectly as it is not looping back up to the Main_Macro to then go to the next cell in "I". It just keeps looping threw sub A_macro() as that is the first one in column "I"
What am I doing wrong?

I have added it as follows:

Sub main_macro()
Dim myLastRow As Long
Dim cell As Range

' Find last row before first blank in column I
myLastRow = Range("I1").End(xlDown).Row

' Loop through all cells in column I until the first blank
For Each cell In Range("I1:I" & myLastRow)
'Your code here
Next cell

If Range("I7").Value = "A" Then
Call A_Macro
ElseIf Range("I7").Value = "B" Then
Call B_macro
ElseIf Range("I7").Value = "C" Then
Call C_macro
ElseIf Range("I7").Value = "D" Then
Call D_macro
Else
Return
End If

End Sub
Sub A_Macro()

Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim Location As String
Dim rDirList As String

Application.ScreenUpdating = False
wdMonth = Sheets("Cover").Range("F7").Value
wdPath = Sheets("Cover").Range("G7").Value
OWFP = Sheets("Cover").Range("F7").Value
Details = Sheets("Cover").Range("H7").Value
TWB = ThisWorkbook.Name
Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))

For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value
Application.Workbooks.Open (wdPath)
Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows(wdMonth).Activate
Sheets(Details).Select

ActiveSheet.Range("f802:aq803").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next

End Sub
 
Upvote 0
Code:
Sub main_macro()
Dim myLastRow As Long
    Dim cell As Range
    
'   Find last row before first blank in column I
    myLastRow = Range("I1").End(xlDown).Row
    
'   Loop through all cells in column I until the first blank
    For Each cell In Range("I1:I" & myLastRow)
        'Your code here
    Next cell
    
       If Range("I7").Value = "A" Then
           Call A_Macro
       ElseIf Range("I7").Value = "B" Then
           Call B_macro
        ElseIf Range("I7").Value = "C" Then
           Call C_macro
        ElseIf Range("I7").Value = "D" Then
           Call D_macro
       Else
           Return
       End If
          
   End Sub
Sub A_Macro()
       
Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim Location As String
Dim rDirList As String
 
Application.ScreenUpdating = False
    wdMonth = Sheets("Cover").Range("F7").Value
    wdPath = Sheets("Cover").Range("G7").Value
    OWFP = Sheets("Cover").Range("F7").Value
    Details = Sheets("Cover").Range("H7").Value
    TWB = ThisWorkbook.Name
    Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))
    
For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value
Application.Workbooks.Open (wdPath)
Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Windows(wdMonth).Activate
Sheets(Details).Select
 
ActiveSheet.Range("f802:aq803").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next
        
End Sub

   Sub B_macro()
       Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
    wdMonth = Sheets("Cover").Range("F7").Value
    wdPath = Sheets("Cover").Range("G7").Value
    OWFP = Sheets("Cover").Range("F7").Value
    Details = Sheets("Cover").Range("H7").Value
    TWB = ThisWorkbook.Name
    Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))
    
For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value
Application.Workbooks.Open (wdPath)
Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Windows(wdMonth).Activate
Sheets(Details).Select
 
ActiveSheet.Range("f803:aq805").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next
End Sub
   
Sub C_macro()
       Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
    wdMonth = Sheets("Cover").Range("F7").Value
    wdPath = Sheets("Cover").Range("G7").Value
    OWFP = Sheets("Cover").Range("F7").Value
    Details = Sheets("Cover").Range("H7").Value
    TWB = ThisWorkbook.Name
    Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))
    
For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Windows(wdMonth).Activate
Sheets(Details).Select
 
ActiveSheet.Range("f804:aq806").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select
Next
End Sub
Sub D_macro()
       Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
    wdMonth = Sheets("Cover").Range("F7").Value
    wdPath = Sheets("Cover").Range("G7").Value
    OWFP = Sheets("Cover").Range("F7").Value
    Details = Sheets("Cover").Range("H7").Value
    TWB = ThisWorkbook.Name
    Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))
    
For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Windows(wdMonth).Activate
Sheets(Details).Select
 
ActiveSheet.Range("f1004:aq1006").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select

Next
End Sub
 
Upvote 0
Your code needs to go within the loop, where I put the line 'Your code here
You placed it after the loop!

Also, you have it referencing a hard-code cell address (I7), instead of looping through the cells.

If you want it to start at row 7, it should look something like this (I also used a CASE statement instead of a whole bunch of IF statements):
Code:
Sub main_macro()    
    Dim myLastRow As Long
    Dim cell As Range
    
'   Find last row before first blank in column I, starting on row 7
    myLastRow = Range("I7").End(xlDown).Row
    
'   Loop through all cells in column I until the first blank
    For Each cell In Range("I7:I" & myLastRow)
        Select Case cell.Value
            Case "A"
                Call A_Macro
            Case "B"
                Call B_macro
            Case "C"
                Call C_macro
            Case "D"
                Call D_macro
        End Select
    Next cell
          
End Sub
 
Last edited:
Upvote 0
I am still having issues as it is not looping back to the main_macro. it just keeps going thru A_Macro and errors out. I think my issue is that after I close out the workbook it is copying from it is not returning to my original workbook. Is that correct? How can I resolve this issue?
this is the code it is getting stuck in:
Code:
Sub D_macro()
       Dim wdMonth As String
Dim wdPath As String
Dim Details As String
Dim OWFP As String
Dim Tb As String
Dim PCP As String
Dim TWB As String
Dim NextRow As Range
Dim WKBK As Workbook
Dim TABNM As String
Dim WNAME As String
Dim pRange As Range
Application.ScreenUpdating = False
    wdMonth = Sheets("Cover").Range("F7").Value
    wdPath = Sheets("Cover").Range("G7").Value
    OWFP = Sheets("Cover").Range("F7").Value
    Details = Sheets("Cover").Range("H7").Value
    TWB = ThisWorkbook.Name
    Application.Workbooks.Open (wdPath)
Application.DisplayAlerts = False
Windows(TWB).Activate
NetNum = Application.WorksheetFunction.CountA(Range("$B$7:$B$51"))
    
For network = 7 To 6 + NetNum
wdMonth = Sheets("Cover").Cells(network, 6).Value
wdPath = Sheets("Cover").Cells(network, 7).Value
TABNM = Sheets("Cover").Cells(network, 8).Value

Windows(wdMonth).Activate
Sheets(Details).Select
Sheets(TABNM).Range("D2").Select
Sheets(TABNM).Range("D2").Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Windows(wdMonth).Activate
Sheets(Details).Select
 
ActiveSheet.Range("f1004:aq1006").Select
Selection.Copy
Windows(TWB).Activate
Sheets("Details").Select
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
Workbooks(wdMonth).Close SaveChanges:=False

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Windows(TWB).Activate
Sheets("Cover").Select

Next
End Sub
 
Upvote 0
Which line is it choking on?

If you aren't sure, place a break-point at the top of the code and run the macro.
Then, when it stops at the break-point, hit F8 repeatedly to step through the code one line at a time until the problem arises.
 
Last edited:
Upvote 0
Here is what is happening: after it runs all the way thru Sub B_macro() instead of going back to the main macro to then go to loop to the "next" item in line and go to the right sub macro, it just goes back to the top of Sub B_macro() and runs pulling up the next item in line so it is using the wrong sub macro.

Any idea of what is going wrong?
 
Upvote 0
It is hard to made heads or tails of your code, as it all blends together and has no indentation.
What line in Macro_B seems to be sending it to the wrong place?

BTW, is this code that you wrote, or inherited?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top