Excel crashing when executing this code

exceluser90

New Member
Joined
Jun 1, 2011
Messages
15
Worksheets("Main").Range(Cells(17, 1), Cells(getLastRow(2), getLastCol(18))).Copy

I'm pretty new to this, but basically getLastRow and getLastCol get the last row or column in column or row designated, respectively.

I'm trying to copy all of the cells in row 17 and below.

Any help would be appreciated.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Why do the variables getLastRow and getLastCol have (2) and (18) after them respectively?
 
Upvote 0
Welcome to the board.

Can you elaborate, I'm not sure I understand what the functions getLastRow and getLastCol are actually doing. Can you provide an exmaple, I'm sure there's another way to avoid using them since that's the only part of your code that I can see having potential problems.
 
Upvote 0
And how do you determine what values got into getLastRow and getLastCol . If you're happy with 2 and 18 respectively, then try:
Rich (BB code):
Dim r as Long, c as Long
r = Cells(Rows.Count, 2).End(xlUp).Row
c = Cells(18, columns.Count).End(xltoLeft).Column
Sheets("Main").Range(Cells(17, 1), Cells(r, c)).Copy
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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