Excel VBA: Print Preview for Selected Range (5 Examples)

The article will show you some methods on how to print previews for a selected range of cells in Excel by using Microsoft Visual Basic for Application (VBA). If you have a dataset that contains lots of information but you don’t want to print all of it, rather you want partial information of that dataset, you can use VBA effectively in that case. Before printing worksheets, it’s safe to check the print preview for the worksheets so that no errors remain and how they will look after printing. In the following dataset, we have information about several employees of Armani Group.

excel vba print preview selected range


Excel VBA to Show Print Preview for Selected Range (Quick View)

Sub Print_Range_Method()
Sheets("Range Method").Select
Range("B4:F9").Select
ActiveSheet.PageSetup.PrintArea = "B4:F9"
ActiveWindow.SelectedSheets.PrintOut From:=1, _
To:=1, Copies:=1, Collate:=True
End Sub

excel vba print preview selected range


How to Show Print Preview for Selected Range in Excel VBA: 5 Examples

1. Apply Excel VBA PrintOut Method to Show Print Preview Selected Range

Now I’ll show how to print the preview selected range using a simple VBA code. It’s very helpful for some particular moments. From our dataset, we will print the preview selected range using a simple VBA code. Let’s follow the instructions below to print the preview-selected range using a simple VBA code!

Step 1:

  • First of all, open a Module, to do that, firstly, from your Developer tab, go to,

Developer → Visual Basic

Apply Excel VBA PrintOut Method to Print Preview Selected Range

  • After clicking on the Visual Basic ribbon, a window named Microsoft Visual Basic for Applications – Print Preview Selected Range will instantly appear in front of you. From that window, we will insert a module for applying our VBA code. To do that, go to,

Insert → Module

Step 2:

  • Hence, the Print Preview Selected Range module pops up. In the Print Preview Selected Range module, write down the below VBA.
Sub Print_Preview_Selected_Range()
Range("B4:F15").PrintOut
End Sub

Apply Excel VBA PrintOut Method to Print Preview Selected Range

  • Hence, run the VBA.  To do that, go to,

Run → Run Sub/UserForm

Step 3:

  • After running the VBA Code, the Save window will appear. The range you chose, will be saved as PDF if you choose PDF and in the given location of your drive. Give the PDF file a name. In this case, I named my file PrintOut.
  • Click Save.

Apply Excel VBA PrintOut Method to Print Preview Selected Range

  • After that, you can find the file in that location. Open it and you will see the range you have chosen.

  • You can see the print preview of this selected range of cells if you want by pressing CTRL + P and giving the necessary commands.

Read More: Excel VBA: Print Range of Cells


2. Defining the Excel Sheet to Show Print Preview Selected Range by Excel VBA

In this method, we will define the sheet name to print a preview of the selected range by Excel VBA. This is an easy and time-saving way also. Let’s follow the instructions below to print a preview of the selected range by Excel VBA!

Step 1:

  • First, according to method 1, insert a new module and type the below VBA code to multiply the cells. The VBA code is,
Sub Define_Sheet()
Sheets("Define Sheet").Range("B4:F10").PrintOut
End Sub

Defining the Excel Sheet to Print Preview Selected Range by Excel VBA

  • Further, run the VBA.  To do that, go to,

Run → Run Sub/UserForm

Step 2:

  • After running the VBA Code, the Save window will appear. The range you chose, will be saved as PDF if you choose PDF and in the given location of your drive. Give the PDF file a name. In this case, I named my file Define Sheet.
  • Click Save.

Defining the Excel Sheet to Print Preview Selected Range by Excel VBA

  • After that, you can find the file in that location. Open it and you will see the range you have chosen.

Defining the Excel Sheet to Print Preview Selected Range by Excel VBA

  • You can see the print preview of this selected range of cells if you want by pressing CTRL + P and giving the necessary commands.

Read More: Excel VBA: Set Print Area for Multiple Ranges


3. Use Print Preview Selected Range to Print by Excel VBA

Another way to print a range of cells by VBA is to select the range that we prefer to print the preview. Suppose you want to print only the selected range of cells from our dataset. Let’s follow the instructions below to print a preview of the selected range by Excel VBA!

Step 1:

  • First, select a range of cells from our dataset. We will select the cells from B2 to F9 for the convenience of our work.

Use Print Preview Selected Range to Print by Excel VBA

  • After that, according to method 1, insert a new module and type the below VBA code to multiply the cells. The VBA code is,
Sub Selection_of_Print_Preview()
Range("B2:F9").PrintOut
End Sub

  • Further, run the VBA.  To do that, go to,

Run → Run Sub/UserForm

Use Print Preview Selected Range to Print by Excel VBA

Step 2:

  • After running the VBA Code, the Save window will appear. The range you chose, will be saved as PDF if you choose PDF and in the given location of your drive. Give the PDF file a name. In this case, I named my file Selection.
  • Click Save.

  • After that, you can find the file in that location. Open it and you will see the range you have chosen.

Use Print Preview Selected Range to Print by Excel VBA

  • You can see the print preview of this selected range of cells if you want by pressing CTRL + P and giving the necessary commands.

Read More: Excel VBA to Display Print Preview for Multiple Sheets


4. Define Selected Range in the VBA Code to Show Print Preview Selected Range

We can also print a range of cells by VBA using the Range Method. Suppose you want to print the information about the first four persons. Let’s go through the procedure below!

Step 1:

  • First, according to method 1, insert a new module and type the below VBA code to multiply the cells. The VBA code is,
Sub Print_Range_Method()
Sheets("Range Method").Select
Range("B4:F9").Select
ActiveSheet.PageSetup.PrintArea = "B4:F9"
ActiveWindow.SelectedSheets.PrintOut From:=1, _
To:=1, Copies:=1, Collate:=True
End Sub

Define Selected Range in the VBA Code to Print Preview Selected Range

  • Hence, run the VBA.  To do that, go to,

Run → Run Sub/UserForm

Step 2:

  • After running the VBA Code, the Save window will appear. The range you chose, will be saved as PDF if you choose PDF and in the given location of your drive. Give the PDF file a name. In this case, I named my file Range Method.
  • Click Save.

Define Selected Range in the VBA Code to Print Preview Selected Range

  • After that, you can find the file in that location. Open it and you will see the range you have chosen.

Define Selected Range in the VBA Code to Print Preview Selected Range

  • You can see the print preview of this selected range of cells if you want by pressing CTRL + P and giving the necessary commands.

5. Printing Preview Selected Range by Excel VBA With Statement

Last but not least, VBA With Statement can play a vital role in printing a range of cells. From our dataset, we will be able to print previews with statements in VBA code. Let’s follow the instructions below to learn!

Step 1:

  • First, according to method 1, insert a new module and type the below VBA code to multiply the cells. The VBA code is,
Sub Print_Preview_With_Statement()
With Sheets("Statement")
.PageSetup.PrintArea = "B4:F15"
.PrintOut
End With
End Sub

Printing Preview Selected Range by Excel VBA With Statement

  • Further, run the VBA.  To do that, go to,

Run → Run Sub/UserForm

Step 2:

  • After running the VBA Code, the Save window will appear. The range you chose, will be saved as PDF if you choose PDF and in the given location of your drive. Give the PDF file a name. In this case, I named my file Statement.
  • Click Save.

Printing Preview Selected Range by Excel VBA With Statement

  • After that, you can find the file in that location. Open it and you will see the range you have chosen.

  • You can see the print preview of this selected range of cells if you want by pressing CTRL + P and giving the necessary commands.

Things to Remember

👉 You can also pop up the Microsoft Visual Basic for Applications window by pressing Alt + F11 simultaneously on your keyboard.

👉 If a Developer tab is not visible in your ribbon, you can make it visible. To do that, go to,

File → Option → Customize Ribbon


Download Practice Workbook

Download this practice workbook to exercise while you are reading this article.


Conclusion

I hope all of the suitable methods mentioned above to print preview selected ranges with VBA code will now provoke you to apply them in your Excel spreadsheets with more productivity. You are most welcome to feel free to comment if you have any questions or queries.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Md. Abdur Rahim Rasel
Md. Abdur Rahim Rasel

MD. ABDUR RAHIM is a marine engineer proficient in Excel and passionate about programming with VBA. He views programming as an efficient means to save time while managing data, handling files, and engaging with the internet. His interests extend to Rhino3D, Maxsurf C++, AutoCAD, Deep Neural Networks, and Machine Learning, reflecting his versatile skill set. He earned a B.Sc in Naval Architecture & Marine Engineering from BUET, and now he has become a content developer, creating technical content... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo