I am new to writting macros, I have tried two different methods to set the range for the PrintArea in a macro, neither work, See below
Sub CountRows()
Dim RowCount As Integer
Dim FinalCell As String
Dim row1 As Integer
Dim colstart As String
Dim colend As String
Dim RowsE As Double
row1 = 8 'Beginning ROW number
colstart = "$A$8" 'PrintArea Starting location
colend = "$J$" 'PrintArea ending column
'Calculate the number of rows in the spreadsheet
Dim NumberOfRows As Long
With Sheet1
NumberOfRows = .Cells(.Rows.Count, 1).End(xlUp).Row
NumberOfRows = .Range("A" & .Rows.Count).End(xlUp).Row
MsgBox NumberOfRows
End With
FinalCell = colend & NumberOfRows 'PrintArea ending cell
MsgBox FinalCell
'Worksheets("Parts List").PageSetup.PrintArea = "$A$8:$J$26" ' THIS WORKS
'Worksheets("Parts List").PageSetup.PrintArea = "$A$8:FinalCell"
'Worksheets("Parts List").PageSetup.PrintArea = "Cells(8,1):Cells("FinalCell",10)"
'Worksheets("Parts List").PageSetup.PrintArea = "Cells(8,1):Cells(26,10)" 'THIS WORKS
End Sub
What am I doing wrong?
Thanks
Bookmarks