+ Reply to Thread
Results 1 to 4 of 4

Print Non-Blank Cells from CommandButton in Userform

  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    texarkana, Texas
    MS-Off Ver
    Office 2010
    Posts
    2

    Print Non-Blank Cells from CommandButton in Userform

    I have a VBA that does print the desired print area; however, I need the VBA code to hide blank cells during print preview

    Private Sub cmd_PrintPreview_Click()
    Me.Hide
    Dim curPrinter As String
    curPrinter = Application.ActivePrinter
    ActiveWindow.ActiveSheet.PrintPreview
    Application.ActivePrinter = curPrinter
    Me.Show
    End Sub



    I do have a Macro: That will hide empty cells in a range but can't figure out how to insert (Call Print_NonBlank_Rows) as a print preview


    Sub Print_NonBlank_Rows()
    Dim rng As Range, cell As Range, toHide As Range
    Dim r&, c%, b%, n%
    Set rng = ActiveSheet.UsedRange
    For r = 1 To rng.Rows.Count
    b = 0
    For c = 1 To rng.Columns.Count
    If rng.Cells(r, c).Value = 0 Then
    b = b + 1
    End If
    Next c
    If b = rng.Columns.Count Then
    If n = 0 Then
    Set toHide = rng.Cells(r, c).EntireRow
    n = 1
    Else
    Set toHide = Union(toHide, rng.Cells(r, c).EntireRow)
    End If
    End If
    Next r
    toHide.EntireRow.Hidden = True
    ActiveSheet.PrintOut Copies:=1
    toHide.EntireRow.Hidden = False
    End Sub


    Any help or suggestions, please!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Print Non-Blank Cells from CommandButton in Userform

    Replace this line with

    Please Login or Register  to view this content.
    To

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    02-11-2013
    Location
    texarkana, Texas
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: Print Non-Blank Cells from CommandButton in Userform

    Thank You, Sixthsense

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Print Non-Blank Cells from CommandButton in Userform

    Glad it helps you and thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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