VB script for Excel spreadsheet printing

I wish to write a vba script I can run for a spreadsheet in MS Excel that only prints only the rows for a column (let's say columnd) where the cells are not null (or zero).

 The reason for this is that the rows total more than 100, and printing things out for only 20 actually needed entries seem silly.

Before anyone asks, MS Access is not an option. 

 

 


Share Send to a friend Watch Report
 

Best Answer

 
258 helpful answers

Ok, I really stumbled on this one.

 A friend got me through the hurdle.  And walked me through it.

So here goes.  Design the button, edit the code for it

here's the code for mine

rivate Sub CommandButton1_Click()

    Dim i, j As Integer

    ActiveSheet.Unprotect
   
    i = 2
    j = 2
    Do
       
        Do While Cells(j, 15) = "" And Cells(j, 1) <> "ENDOFLIST"
            j = j + 1
        Loop
               
        If j > i Then
            Range("A" & i & ":P" & j).Select
            Selection.EntireRow.Hidden = True
        End If
        i = j
       
        Do While Cells(j, 15) <> "" And Cells(j, 1) <> "ENDOFLIST"
            j = j + 1
        Loop
       
        Range("A" & i & ":P" & j).Select
        Selection.EntireRow.Hidden = False
        i = j
     
    Loop Until Cells(i, 1) = "ENDOFLIST"
   
    ActiveSheet.PageSetup.PrintArea = "$A$1:$p$" & i
    ActiveWindow.SelectedSheets.PrintPreview
 
    Range("A1:P" & i).Select
    Selection.EntireRow.Hidden = False
   
 
End Sub

'it's dynamic to the active sheet, so wow I really was impressed with the simplicity of it. 

Posted 2008-04-15T16:05:34Z
Helpful?(2)
Rated as Best Answer

 

Sign in to participate

Got an answer for JtotheA? Would you like to comment on the posted answers, or vote for the one which you think is the best?

Sign up for a free account, or sign in (if you're already a member).

Explore Related Questions

Other people asked questions on similar topics, check out the answers they received:


Q:

Sample Succession PLans in Excel FOrmat

Does anyone have ideas for excel sheet for succesion plans?
Submitted by careymm   5 months ago.
  • viewed 210 times


Q:

Tabs in MS Excel

Is there a way to display multiple tabs in MS Excel over two or more rows? I have many tabs and switching between them, while not ...
Submitted by drabsv   3 years ago.
  • viewed 1797 times
Last answer posted 3 years ago by EscApe


Q:

MS Excel 2007 Beta 2 - draw borders

Might be stupid but I can't find the "draw border" buttons on MS Excel 2007 Beta 2.
Submitted by drabsv   3 years ago.
  • viewed 1372 times
Last answer posted 3 years ago by drabsv



» More...

Feed - Subscribe to changes to this Q&A Blog
ADVERTISEMENT
ADVERTISEMENT
AOL Autos Q&A is powered by Yedda an AOL Company
Copyright © 2006-2009, Yedda Inc. and respective copyright owners