VB Code - Find last row of data in a column

Rahiem

New Member
Joined
Mar 2, 2009
Messages
17
I am trying to setup a macro that formats my invoices sheets. The macro that I recorded is running okay but the print range is too large for the invoice and I don't want it set at one print range. I want excel to find the last row and column of data per set print range. In this case I have one invoice but problaly need two print ranges or ranges with variables setup to read last row of data from rows A1 to K1 End.xldown. The invoice row range varies from A1 to A150 but I want the print range to fit exactly the same size as my invoice. Here is what I have recorded please help me finx this. Thanks RG,

Range("B7").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=18
ActiveWindow.SmallScroll Down:=5
ActiveSheet.PageSetup.PrintArea = "A1:K100"
Range("B65536").End(xlUp).Select
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.PageSetup.PrintArea = "A1:K100"
ActiveWindow.SmallScroll Down:=-55
End Sub:)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Did the code work? If you got an error message click the Debug button - which line is highlighted?
 
Upvote 0
The code works for me, there are no errors and nothing is highlighted in yellow.

Make sure that you copy and paste exactly

Code:
Sub AddTotals()
Dim LR As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
With Range("A" & LR + 1)
    .Value = "Totals:"
    .Font.Bold = True
End With
With Range("H" & LR + 1)
    .Formula = "=SUM(H2:H" & LR & ")"
    .Font.Bold = True
    .NumberFormat = "0.00"
End With
End Sub
 
Upvote 0
It works but there is some small problem, I need the data to be sorted by column H and range G1:H End.xldown before totals and format number. This macro is suppose to be designed to format a CSV file. Any ideas.
 
Upvote 0

Forum statistics

Threads
1,216,932
Messages
6,133,589
Members
449,816
Latest member
amahmud1

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