0 votes
in VBA by Beginner (20 points)

hello, guys 

I would code to "save as pdf" but only the filled data. I designed an invoice in sheet 1 but I would like the pdf to ignore the rows that are empty beginning  from A19:A32  with condition A19:D32 =" "  then delete the rows after I attached what I wanted in sheet1.

What I want is to press the macro button and create a sheet like this: 

 

 

by Expert (758 points)
Is your range a table?
You can simply loop and hide the empty rows in the desired column then export the sheet to pdf ..
by Beginner (20 points)
not a table  i design this  and i would vba macro automatically not manually

1 Answer

+1 vote
by Expert (758 points)
selected by
 
Best answer

Try this code

Sub Test()
    Dim c As Range, spath As String
    
    Application.ScreenUpdating = False
        With Worksheets("Sheet1")
            For Each c In .Range("A19:A32")
                If Application.Count(c.Resize(1, 4)) = 0 Then
                    c.EntireRow.Hidden = True
                End If
            Next c
        
            spath = ThisWorkbook.Path & "\Output.pdf"
            .ExportAsFixedFormat Type:=xlTypePDF, Filename:=spath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
            .Range("A19:A32").EntireRow.Hidden = False
        End With
    Application.ScreenUpdating = True
End Sub

 

by Beginner (20 points)
+1

 thanks so much  mr  YasserKhalil  the code does perfect work    i appreciate your help 

i would another demand  could  save just one page what contains the data  and delete the rest of pages 

by Expert (758 points)
You're welcome. The code is already exports just the sheet1 not the other sheets.
by Beginner (20 points)
I know  but what  I  ment  here  when  you  open  file  pdf  here  you see more  than  one  page  just  the  page  one contains  data   and  the rest are empty  according  this  I would  just  the  page  contains  data
by Expert (758 points)
Did you try to set the print area .. so as to print out specific range?
by Beginner (20 points)
Can  you  more  explaining  I don't  understand  you
by Expert (758 points)
Select the desired range that you would like to print >> Page layout tab >> Print Area >> Set Print Area .. This will make the exported PDF is limited to this area only

You can record macro and implement that into your code if you wish
by Beginner (20 points)
Thanks  I try  this

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...