Macro help needed

gabriellejayde

New Member
Joined
Apr 18, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I am not great with macros and can't figure this one out. This is the current macro we use to copy a cell range:

Sub CopyInventory()
'
' CopyInventory Macro
' FROM INVENTORY MANAGER

'
Range("F33:O5000").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
End Sub

So it's copying almost 5000 rows. column F is filled with a formula down to row 5000, but often we only have a few hundred rows of columns G-O filled. Rather than always copying down to row 5000, I'd like to only copy columns F through O down to the last filled row in column G. (because column F is filled with a formula).

Does anyone know how to do this?
 

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.
Code:
Dim r As Long

Range("G1").Select
Selection.End(xlDown).Select
r = ActiveCell.Row
Range("F1:O" & r).Select
Selection.Copy
 
Upvote 0
Your Range(Selection, Selection.End(xlDown)).Select indeed select up to the latest row in the worksheet (1 Mill; much worse than 5000)
So if you remove that line things will be much better.

You can copy the populated rows only by using, for exampèle:
VBA Code:
LR = Evaluate("MAX((F33:O5000<>"""")*ROW(F33:O5000))")
Range("F33:O" & LR).Copy
This in addition to what already suggested by RanMan, above
 
Upvote 0
Solution
Code:
Dim r As Long

Range("G1").Select
Selection.End(xlDown).Select
r = ActiveCell.Row
Range("F1:O" & r).Select
Selection.Copy

Thanks... but that copied the whole workbook. I just want to copy columns F-O, from line 33 down to the last filled line in column G. If I don't specify which column, I'll get the whole spreadsheet because column F is filled with a formula down to line 5000.
 
Upvote 0
Hi. i just did it and it worked. it selects the bottom cell in the spreadsheet, but it's copying the right info so it's fine. Thank you for your help!!
Thank you for the feedback, but my code don't select any cell...
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,118
Members
449,066
Latest member
Andyg666

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