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
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