Copying Range From Specific Sheets into Different Specific Sheets in Another Workbook with Nested For Next

TryingtoLearnVBA

New Member
Joined
Jul 30, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
First Time Post Here.
I have two Workbooks one with daily data for the Month and one with shift data for the Month. Each of these workbooks has summation tabs at the beginning and end of the workbook. The ranges are not the same in the workbooks and there are twice as many sheets to copy to. The sheet names change on a monthly basis also.
I am trying to copy the data from the daily into the corresponding shift tab. What I have so far copy's the range from the daily into the 1st specified worksheet for the entire loop.
I am thinking I have the wrong approach to get this done. Any help would be appreciated and please let me know if I need to clarify more.

Thanks

VBA Code:
[
Option Explicit

Sub CopyData()
 Application.Calculation = xlCalculationManual
    Application.DisplayStatusBar = False
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
 
Dim j As Integer
Dim i As Integer
Dim Filename1 As String
 
 Filename1 = "JulyDailyData"


  For i = 6 To 66 Step 2
 For j = 2 To 32

 Workbooks(Filename1).Worksheets(j).Range("J12:K26").Copy
 ThisWorkbook.Worksheets(i).Range("Q11:R25").PasteSpecial Paste:=xlPasteValues
 
 Next j
 Next i
      
    Application.Calculation = xlCalculationAutomatic
    Application.DisplayStatusBar = True
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I figured out the issue, Nested for statements were causing the issue. Solution Below
VBA Code:
[/
 For i = 6 To 66 Step 2
   j = (i / 2) - 1

 Workbooks(Filename1).Worksheets(j).Range("J12:K26").Copy
 
 
 ThisWorkbook.Worksheets(i).Range("Q11:R25").PasteSpecial Paste:=xlPasteValues
 
 Next i
]
 
Upvote 0
Solution

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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