select data

klatlap

Well-known Member
Joined
Sep 1, 2004
Messages
607
Office Version
  1. 2013
Platform
  1. Windows
I need a macro that would copy cells BA2:QG? now i don't know what the last row will be as it changes.

I have used this code before but the empty cells are copied as well.

Code:
Sub Copy()
Sheets("Data").Select
    Range("BA2:QG25").Select
    Selection.Copy
    Sheets("Output").Range("A" & Sheets("Data").Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=True, Transpose:=False
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Maybe try
Code:
Sub Copy()
dim lr as Long
lr = cells(rows.count."QG").end(xlup).row
Sheets("Data").Range("BA2:QG" & lr).Copy
    Sheets("Output").Range("A" & Sheets("Data").Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=True, Transpose:=False
 
Upvote 0
Must be error in code as soon as i paste it i get an error on the 3rd line
 
Upvote 0
ooops....that's what happens when you type in the dark
Code:
Sub Copy()
dim lr as Long
lr = cells(rows.count,"QG").end(xlup).row
Sheets("Data").Range("BA2:QG" & lr).Copy
    Sheets("Output").Range("A" & Sheets("Data").Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=True, Transpose:=False
 
Upvote 0
Since multiple sheets are involved I would strongly recommend adding
Rich (BB code):
lr = Sheets("Data").Cells(Rows.Count, "QG").End(xlUp).Row

Also, should work OK, but seems strange to use "Data" to count the rows in the last line of code when you are working on "Output". (No sheet was specified when counting the rows to determine lr)
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,847
Members
452,948
Latest member
UsmanAli786

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