Hello
this code works very well, but I need when save the file as PDF shouldn't show empty rows based range B:F
the column A always filled numbers 1,2... and column G is filled formula . so I want dealing for columns B21:F if this range is empty .
I have two challenges :
1- I have word TOTAL in lastrow for column A and columns B:F in TOTAL row will be empty ,then I'm afraid will delete TOTAL row if I depend on B: F to hide rows .
2- will add new rows before TOTAL row so I can't specify specific range
last thing when hide row should just show when save the file as PDF but the excel file should keep as in orginal data without hid any rows after save the file .
Public Sub Save_Columns_As_PDF()
Dim mainFolder As String, subfolder As String, PDFfile As String
Dim lastRow As Long
mainFolder = "C:\Users\pc\Desktop\ARCHIVE\"
If Right(mainFolder, 1) <> "\" Then mainFolder = mainFolder & "\"
With ActiveWorkbook.Sheets("SH1")
subfolder = mainFolder & .Range("G1").Value & "\"
If Dir(subfolder, vbDirectory) = vbNullString Then MkDir subfolder
subfolder = subfolder & UCase(Format(Date, "mmm")) & "\"
If Dir(subfolder, vbDirectory) = vbNullString Then MkDir subfolder
PDFfile = subfolder & .Range("G6").Value & ".pdf"
lastRow = .Range("A:G").Find("*", , , , xlByRows, xlPrevious).Row
.Range("A1:G" & lastRow).ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
MsgBox "Created " & PDFfile, vbInformation
End Sub
thanks in advance .