Copying data within a page break

PamL

New Member
Joined
Nov 22, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm new to coding things using vba. I'm trying to create pdfs for staff members showing data relating to their class that has their initials and class code as their file name. So far I'm copying the required data into a new page, hiding the columns that aren't needed and saving as a pdf. The issue I'm having is getting this to repeat for data within the next page break. As classes have a different number of students the number of rows between each page break varies. There are up to 500 classes so this really needs to be automated. I'd be really grateful if someone could help me with this as I'm stumped.



Sub CreateStaffPDFs()

'Copy Data

Range("C23:AB49").Select
Selection.Copy
Sheets("Sheet23").Select
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

'Hide columns

Columns("E:E").Select
Range("E3").Activate
Selection.EntireColumn.Hidden = True
Columns("H:J").Select
Range("H3").Activate
Selection.EntireColumn.Hidden = True

'Save to pdf - file name is found using concat of two cells which is generated in C1.

Dim fileName As String

fileName = Range("C1").Text

ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
fileName:=fileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

Application.CutCopyMode = False

'
' Repair Sheet

'
Range("A5:Z39").Select
Selection.ClearContents
Columns("D:K").Select
Selection.EntireColumn.Hidden = False
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You can code around page breaks, but that is very awkward. There must be another defining item. If Excel didn't have pagebreaks you could easily distinguish which section belongs to which teacher. So which keywords, or changes in cells define the next section?

That is what you want to search for with your macro. Then find the next section and print anything in between
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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