+ Reply to Thread
Results 1 to 3 of 3

Macro Keeps Saving Blank Rows as Part of PDF

  1. #1
    Registered User
    Join Date
    04-06-2021
    Location
    Argentina
    MS-Off Ver
    2013
    Posts
    1

    Macro Keeps Saving Blank Rows as Part of PDF

    I have a large data set that varies each month. There's an IF formula in there that always turns up many blank cells:

    Example:
    =IF($B58<>"",VLOOKUP($B58,'Product Description '!$B$9:$D$40000,11,0),"")

    As a result of these cells being blank, but having underlying formulas, my Excel to PDF macro keeps saving a bunch of blank pages. My goal is to have Excel convert to PDF ONLY the visible data, not the blank cells with underlying formulas.

    Here is my code that results in saving my worksheet as a PDF, but giving me extra pages. What am I missing here?

    Sub savepdfwithcorrectpages()

    Dim ID As String

    Dim ws As Worksheet, R As Range, Rw As Range, Ct As Long, Cel As Range


    For Each ws In ActiveWorkbook.Worksheets
    On Error Resume Next
    Set R = ws.UsedRange.SpecialCells(xlCellTypeFormulas)
    If Err.Number <> 0 Then
    Err.Clear
    GoTo Nx
    End If
    For Each Rw In R.Rows
    For Each Cel In Rw.Cells
    If Cel.Value = "" Then Ct = Ct + 1
    If Ct = Rw.Cells.Count Then
    Rw.EntireRow.Hidden = True
    End If
    Next Cel
    Nx: Ct = 0

    Next Rw

    ID = Range("B1").Text

    ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="Desired File\" + ID + ".pdf", _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

    Next ws

    Application.ScreenUpdating = True

    End Sub



  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Macro Keeps Saving Blank Rows as Part of PDF

    Re "not the blank cells"
    You can't hide cells only. you Can hide Rows and/or Columns.
    If you meant to hide the Rows where all the Cells in that Row show blank but with a formula in it, how many Cells(Column wise) need to be checked?
    You can have 12 Columns of Data but only want to print 6 Columns, so no use checking 12 Cells.
    If possible at all, add an attachment with a representative setup and no personal data.
    Explain on the Sheet in question what needs to be done.

    Also, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Last edited by jolivanes; 04-06-2021 at 11:19 PM.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Macro Keeps Saving Blank Rows as Part of PDF

    Does this, more or less adhering to your style, work for you?
    Change the references as and where required.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help with adding shortcut, not copying blank rows, and saving worksheet
    By vlr516 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-28-2017, 03:12 PM
  2. How to save macro when code is prevent saving if there's blank cells ?
    By gilver in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2016, 06:20 AM
  3. [SOLVED] Macro to lock all the Non Blank cells after saving the workbook.
    By adil.master in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2014, 09:35 AM
  4. How to create a macro to insert blank rows and copy data into blank rows?
    By zodiack101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2013, 01:18 PM
  5. [SOLVED] Saving worksheet using a macro. Problem is that it is saving more rows than it needs to
    By Kammphoto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2013, 10:09 AM
  6. 2 part piece here. One part counter of up and down, fill in of blank cells.
    By greenfox74 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-04-2012, 10:09 PM
  7. [SOLVED] Looping Macro That adds a blank row between different part #'s
    By fiero84 in forum Excel General
    Replies: 5
    Last Post: 03-25-2005, 03:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1