Open Excel VBA

woman in black dress shirt using MacBook
Woman in black dress shirt using Excel
  • Open the Microsoft Visual Basic for Applications window.
  • Insert > Module
  • Paste the following code in the window:
Sub PrintOneLine()
Dim Rng As Range
Dim WorkRng As Range
Dim xWs As Worksheet
On Error Resume Next
xTitleId = "SelectRange"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set xWs = WorkRng.Parent
For Each Rng In WorkRng
xWs.PageSetup.PrintArea = Rng.EntireRow.Address
End Sub
  • Press F5 to run the code, and that’s it, a preview window will open so you can preview or print as you see fit.

Tagged in:

, , ,