Get the address to a set PrintArea and use it for copy

ArnMan

Board Regular
Joined
Aug 30, 2017
Messages
69
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I was wondering how can I get the set PrintArea of a sheet and use that address to copy over to another sheet.
Lets call the PrintArea sheet .. Sheet1 and the destination Sheet2
Sheet1 will be a sheet that has been imported from a file. The printareas are all going to be different so I cant just use one range. The print area is set and saved when the file was originally saved. If I can access it while importing, because for some reason, once it is imported the print area is lost. So if I could open the file get the print area first then import it that would be very helpful.
That way once I import the file to Sheet1, I could use that address and copy the previously set PrintArea to Sheet2.

Is there a way to do that?

This is the function I use to open a file for importing.

Code:
Private Sub ImportBut_Click()
Unload entryform
Sheets("Import").Range("A1:BG9999").Clear
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim Sheet As Worksheet
Dim PasteStart As Range
Set wb1 = ActiveWorkbook
Set PasteStart = [Import!A1]
Sheets("Import").Select
    Cells.Select
    Selection.ClearContents
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a Template to Import", _
FileFilter:="Report Files *.xlsx (*.xlsx),")
If FileToOpen = False Then
    MsgBox "No File Specified.", vbExclamation, "ERROR"
   Exit Sub
 Else
    Set wb2 = Workbooks.Open(Filename:=FileToOpen)
    For Each Sheet In wb2.Sheets
        If Sheet.Name = "Datasheet-C" Then
        
                With Sheet.UsedRange
                    .Copy PasteStart
                    Set PasteStart = PasteStart.Offset(.Rows.Count)
                End With
        End If
        If Sheet.Name = "Datasheet" Then
                With Sheet.UsedRange
                    .Copy PasteStart
                   Set PasteStart = PasteStart.Offset(.Rows.Count)
                End With
        End If
    Next Sheet
   
 End If
    wb2.Close
    
    
  
Call ImportDS
    
    
 
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
Sub t()
MsgBox [COLOR=#FFA500]ActiveSheet.PageSetup.PrintArea[/COLOR]
End Sub

Returns the cell address of the set print area. If not print area is set, returns entire sheet.
 
Last edited:
Upvote 0
OO ok awesome that works
Now Can I use that PrintArea range and copy the printArea to another sheet?
Code:
Sub t()
MsgBox [COLOR=#ffa500]ActiveSheet.PageSetup.PrintArea[/COLOR]
End Sub

Returns the cell address of the set print area. If not print area is set, returns entire sheet.
 
Upvote 0
OO ok awesome that works
Now Can I use that PrintArea range and copy the printArea to another sheet?
I don't understand the question. The print area is set as a sub property of the PageSetup property for a sheet. If you want to use the same values on different sheets you could put them in a variable and apply them.
Code:
Dim pa As String
pa = Sheets("Sheet1").PageSetup.PrintArea
Sheets("Sheet2").PageSetup.PrintArea = pa
 
Upvote 0
I apologize for not being very clear on my question.

Lets say I have Sheet1 with a printarea set, and there will be values formula, formatting, etc inside the print area. I want to be able to find the print area. Use the printarea address, and copy everything inside it, and paste that into Sheet2 into the same address or maybe to another range if possible.


I don't understand the question. The print area is set as a sub property of the PageSetup property for a sheet. If you want to use the same values on different sheets you could put them in a variable and apply them.
Code:
Dim pa As String
pa = Sheets("Sheet1").PageSetup.PrintArea
Sheets("Sheet2").PageSetup.PrintArea = pa
 
Upvote 0
Code:
Dim adr As String
adr = Sheet1.PageSetup.PrintArea
Sheet1.Range(adr).Copy Sheet2.Range("A2")

The above would copy the data in print area of sheet 1 to sheet 2, anchored on cell A2.
 
Upvote 0
Thank you very much that works great.

You have been very very helpful.

Code:
Dim adr As String
adr = Sheet1.PageSetup.PrintArea
Sheet1.Range(adr).Copy Sheet2.Range("A2")

The above would copy the data in print area of sheet 1 to sheet 2, anchored on cell A2.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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