Macro to copy formula till second last row

razgra1z

New Member
Joined
Mar 20, 2012
Messages
24
Hello All,

Please guide me how I can adjust these lines to get formula copy till second last cell and not the last one.

Selection.AutoFill Destination:=Range("X2:X" & Range("W" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Range(Selection, Selection.End(xlDown)).Select

Thanks in advance.
 
Last edited:
How about
VBA Code:
Selection.AutoFill Destination:=Range("X2:X" & Range("W" & Rows.Count).End(xlUp).Offset(-1).Row), Type:=xlFillDefault
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hi Fluff,

I want sum in last row and make it bold. I've found following VBA code, how I can insert it in my current macro and make sum bold.

Dim lLastRow As Long
With Sheets("Sheet1") 'put your sheet name here
lLastRow = .Range("X" & .Rows.Count).End(xlUp).Row
.Range("X" & lLastRow + 1).Formula = "=Sum(X2:X" & lLastRow & ")"
End With

Thanks in advance.
 
Upvote 0
Add this
Rich (BB code):
     .Range("X" & lLastRow + 1).Formula = "=Sum(X2:X" & lLastRow & ")"
     .Range("X" & lLastRow + 1).Font.Bold=True
End With
 
Upvote 0
Range("X2").Select
Selection.AutoFill Destination:=Range("X2:X" & Range("W" & Rows.Count).End(xlUp).Offset(-1).Row), Type:=xlFillDefault
Range(Selection, Selection.End(xlDown)).Select
Columns("X:X").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
.Range("X" & lLastRow + 1).Formula = "=Sum(X2:X" & lLastRow & ")"
.Range("X" & lLastRow + 1).Font.Bold = True
Range("X1").Select
ChDir "C:\Users\Adam\Desktop"
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\Adam\Desktop\Inventory Sales Today.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Sheets("Summary").Select

Here is the macro...I've inserted what you've suggested. After copying formula to second last row, I need to convert those formula into values and then I want sum in last row with bold text. The lines I've inserted are not working...may be i am not putting them in right place. Please advise.
 
Upvote 0
You have removed the With Statement, that's why it's not working
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

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