printing where the last data is entered In excel

Copper Contributor
I am giving you an editable workbook that is operational in everything I want it to do except when it comes to the notes area I need to create a button on the left column where there is two other button that are functional . 1 to go to previous worksheet and 2 Archive Notes . the 3 should give me the ability to print just the A1 Cell which is for the month only. then all the data for data for B,C & D . the issue I am having is getting it to print all of the column and row until their is no long data found. plus with the VBA code I create it for some reason was breaking it up into three separate pages the first two columns on one back and one column on the other two pages . its weird. I need it to print out on one sheet even if it had go to landscape mode to do it. here is the below code and a like to my work book. thanks for the help Sub prt() Dim LR As Long With ActiveSheet LR = .Range("D" & Rows.Count).End(xlUp).Row .PageSetup.PrintArea = "A1:D" & LR .PrintOut End With End Sub https://www.dropbox.com/scl/fi/n93kufi68sy08z77f0akg/Blankcount4back.xlsm?rlkey=pqk9nl2sv8od09hwiabx...
1 Reply

@ShawnT1971 

To achieve your desired outcome of printing the data from column A to column D until the last row of data on one sheet, you can maybe adjust your VBA code as follows:

Vba code is untested, please backup your file in advance.

Sub prt()
    Dim LR As Long
    Dim ws As Worksheet
    Dim rngPrint As Range
    
    Set ws = ActiveSheet
    
    ' Find the last row with data in column D
    LR = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row
    
    ' Define the range to print
    Set rngPrint = ws.Range("A1:D" & LR)
    
    ' Set print settings
    With ws.PageSetup
        .PrintArea = rngPrint.Address
        .Orientation = xlLandscape ' Set to landscape mode
        .FitToPagesWide = 1 ' Fit to one page wide
        .FitToPagesTall = False ' Do not fit to pages tall
    End With
    
    ' Print the defined range
    rngPrint.PrintOut
End Sub

Please Note: VBA macros themselves do not directly work in files stored on cloud storage platforms like Dropbox or OneDrive.

However, you can certainly store Excel files containing VBA macros on these platforms. When you open the Excel file from the cloud storage platform, you'll be able to run the macros as usual, provided that you enable macros when prompted and that your Excel settings allow for macros to run.

In other words, the macros are part of the Excel file, not the cloud storage platform itself. So as long as you're opening the Excel file in Excel (whether it's stored locally or in the cloud), the macros will work as intended. Just make sure to always enable macros from trusted sources to avoid potential security risks. The text was created with the help of AI.

 

My answers are voluntary and without guarantee!

 

Hope this will help you.

 

Was the answer useful? Mark as best response and like it!

This will help all forum participants.