Copy range until last occupied cell [VBA]

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi,

I used this macro to copy data from each sheet in the active workbook, from the range A14:BB258 to the MASTER sheet, to the first available row.

As you can see I am using a fixed range (A14:BB258).

I would like to modify this macro to copy exactly same range (A14:BB258), but with little change.
The macro will work until the last occupied cell in the column G.
Therefore, it does not always have to go to the bottom of this range (A14: BB258).

VBA Code:
Sub SUMMARIZE_DATA()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "MASTER" Then
ws.Range("A14:BB258").Copy
Sheets("MASTER").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteAll
End If
Next
Application.CutCopyMode = False
End Sub

Thank you for your help.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi Martin_H
just add a variable to find the lastrow in column G
VBA Code:
Sub SUMMARIZE_DATA()

Dim ws As Worksheet
Dim LastRow As Long

For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "MASTER" Then
LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row
ws.Range("A14:BB" & LastRow).Copy
Sheets("MASTER").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteAll
End If
Next
Application.CutCopyMode = False
End Sub
 
Upvote 0
Solution
Awesome Sequoyah (y)

I appreciate it very much. Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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