Copy a range of cells from 2 worksheets and paste into 1 worksheet using same workbook using VBA

Msears

Board Regular
Joined
Apr 14, 2022
Messages
56
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello All, I am wanting to copy a range of cells (A2:L500) from worksheets "JUL" and "AUG" and paste the date into worksheet ("1st Qtr"). Ideally, I want it to copy the range of data from Jul paste values & formats in the same range, next empty row in 1st Qtr, then copy the same range in Aug and paste the data below Jul in the 1st Qtr sheet. Is this possible using VBA? Thanks in advance!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hello All, I am wanting to copy a range of cells (A2:L500) from worksheets "JUL" and "AUG" and paste the date into worksheet ("1st Qtr"). Ideally, I want it to copy the range of data from Jul paste values & formats in the same range, next empty row in 1st Qtr, then copy the same range in Aug and paste the data below Jul in the 1st Qtr sheet. Is this possible using VBA? Thanks in advance!

Hello - try this:

VBA Code:
Sub copymonth()

'sets sheet array for months, can update to include additional months
Dim shts As Variant: shts = Array(Sheets("July"), Sheets("August"))
'declares 1st Qtr worksheet
Dim qtr1 As Worksheet: Set qtr1 = ThisWorkbook.Sheets("1st Qtr")
'general declarations
Dim Q1lrow As Long, sh As Worksheet, i As Long

'find last row in 1st Qtr sheet based on column A (revise to suit)
Q1lrow = qtr1.Cells(qtr1.Rows.Count, "A").End(xlUp).Row

'loops through shts array copying specified range to 1st Qtr tab
For i = LBound(shts) To UBound(shts)
    With shts(i)
        .Range("A2:L500").Copy
        qtr1.Cells(Q1lrow + 1, 1).PasteSpecial xlPasteValuesAndNumberFormats
    End With
    'updates last row on 1st Qtr tab
    Q1lrow = qtr1.Cells(qtr1.Rows.Count, "A").End(xlUp).Row
Next i

'resets Q1 last row
Q1lrow = vbNull

End Sub
 
Upvote 0
Solution
Hello - try this:

VBA Code:
Sub copymonth()

'sets sheet array for months, can update to include additional months
Dim shts As Variant: shts = Array(Sheets("July"), Sheets("August"))
'declares 1st Qtr worksheet
Dim qtr1 As Worksheet: Set qtr1 = ThisWorkbook.Sheets("1st Qtr")
'general declarations
Dim Q1lrow As Long, sh As Worksheet, i As Long

'find last row in 1st Qtr sheet based on column A (revise to suit)
Q1lrow = qtr1.Cells(qtr1.Rows.Count, "A").End(xlUp).Row

'loops through shts array copying specified range to 1st Qtr tab
For i = LBound(shts) To UBound(shts)
    With shts(i)
        .Range("A2:L500").Copy
        qtr1.Cells(Q1lrow + 1, 1).PasteSpecial xlPasteValuesAndNumberFormats
    End With
    'updates last row on 1st Qtr tab
    Q1lrow = qtr1.Cells(qtr1.Rows.Count, "A").End(xlUp).Row
Next i

'resets Q1 last row
Q1lrow = vbNull

End Sub
Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

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