VBA message input to complete print range

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
I would like to use a macro with a message box response to complete a print range. So let's say I want a print range of A3 to C30, but I want the C30 to change based on the input in the message box. The A3 can remain fixed as that will not likely change. I am new to vba and could not fine anything in the search. Thanks
 
disregard last post. It does work but it wasn't showing the print range outline from some reason. In print preview it showed correctly.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi, the following code was written earlier in this post. Currently it creates a range from A3 to the column letter specified in the input box concatenated with the row number in A1. I need a modified version to also use A3 as the starting point but to find the column to the right (with data) automatically, eliminating the input box. However, there will always be hidden columns to the right of the column I need, but I do not want those included. Those hidden columns will not have data, but will have a couple of rows of titles. If you need to use a row# as criteria, you may use row 40 as there will not be data in that row in the hidden columns (although those hidden cells will have formulas). I hope I provided enough information.

Code:
Sub PRINT_RANGE()
    Dim response As String
    Dim PrintAreaString As String
    response = InputBox("Enter column letter for 2nd part of range", "Enter Data")
      Application.ScreenUpdating = False
      With ActiveSheet
        PrintAreaString = "$A$3:$" & Trim(UCase(response)) & "$" & .Range("A1").Value
        If response <> "" Then
            .PageSetup.PrintArea = PrintAreaString
            .PageSetup.Orientation = xlLandscape
            .PageSetup.Zoom = False
            .PageSetup.FitToPagesWide = 1
            .PageSetup.FitToPagesTall = False
            .PageSetup.LeftMargin = 36
            .PageSetup.TopMargin = 72
            .PageSetup.RightMargin = 36
            .PageSetup.BottomMargin = 36
           
        End If
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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