Copy cell only as far as the previous column cells go down in Macro

Peter Davison

Active Member
Joined
Jun 4, 2020
Messages
444
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a cell F1 which I want to copy in a macro as far down the column as data goes in Column E.
The reason I can't leave a static formula in the cell is because it relates to a chart and if there is a formula in the cells lower than data in column E it will extend the width of the graph.
As I am new to VBA in Excel I'm not sure how to do this. Can you help?
Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
My suggestion was to replace this line of code
VBA Code:
 Range("G2:G" & lr) = Range("G2").Formula
 
Upvote 0
Post a copy of your workbook to a well-known free file sharing website (my recommendation is DropBox) so that we can see why the posted code is not working for your data.
 
Upvote 0
Yes I did replace it with the below, but that did not work it just left the G2 cell with the formula and the rest empty
Range("G2:G" & lr).filldown
I've just tried it again and it definitely does fill the cells.
Does it need to be within its own sub starts and end?
 
Upvote 0
Can you please post the code you are using.
 
Upvote 0
Workbooks("filename").Worksheets("rep writer variance report").Activate
Dim lr As Long: lr = Range("F" & Rows.Count).End(xlUp).Row

Worksheets("rep writer variance report").Range("G4:g" & lr) = Range("G4").Formula
 
Upvote 0
That doesn't have the code change I suggested.
 
Upvote 0
I did change it as per below just changed it back when it didn't work.

Workbooks("filename").Worksheets("rep writer variance report").Activate
Dim lr As Long: lr = Range("F" & Rows.Count).End(xlUp).Row

Range("G2:G" & lr).filldown

and I also tried it with the sheet name in front of "Range"
 
Upvote 0
If you add a message box like
VBA Code:
Dim lr As Long: lr = Range("F" & Rows.Count).End(xlUp).Row
MsgBox lr
Range("G2:G" & lr).filldown
What does it say?
 
Upvote 0

Forum statistics

Threads
1,215,836
Messages
6,127,173
Members
449,368
Latest member
JayHo

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