+ Reply to Thread
Results 1 to 3 of 3

Macro to print only lines with cell value greater than zero

  1. #1
    Registered User
    Join Date
    07-14-2013
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro to print only lines with cell value greater than zero

    Hi,
    I am hoping that someone may be able to help me with this problem which i will try to outline as clearly as possible.

    I have an excel spreadsheet with over 250 rows in it (with more being added regularly). It is essentially being used as a calculator, the idea being if i put a quantity value in column B it would tell me how much they are worth, i could then do this for a number of rows and it would give me a value for each line as well as a total for all rows.

    I then want to print only the lines which had a value in column B.

    I then googled and found a macro which would allow me to do this (I have no real VB knowledge), the macro is as follows:

    Sub PrintActiveLines()
    Application.ScreenUpdating = False
    Range("B:B").EntireRow.Hidden = False
    Range("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Range("B:B").EntireRow.Hidden = False
    Application.ScreenUpdating = True
    End Sub

    This was working perfectly until I added some formulas into column B in some rows, (like "=B30*2") which meant that if there was no value in cell B30 then the total for the formula is 0.

    This means that all rows with a formula in it has a default value of 0 which then prints, but i don't want it to.

    So what i am asking (in a long winded way) is how do i modify the formula so that only prints rows that has a value in Column B greater than zero. (or alternatively, I believe the formula above says "do not print row if column B is empty, how do i modify it so it says "do not print rows if column B is empty or equals zero")

    I hope this all makes sense, This is a first time post ever, if i am unclear please be gentle with me.

  2. #2
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: Macro to print only lines with cell value greater than zero

    Have you tried using auto filter? You can easily record a macro for that.

  3. #3
    Registered User
    Join Date
    07-14-2013
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to print only lines with cell value greater than zero

    Thanks jlt199,

    I have never used filter in excel either but managed to figure it out pretty quickly and create a macro, not only that, I then copied in the screenupdating lines from the original macro to speed it up etc. I now have something that works.

    Thank you for your quick response.
    Last edited by Matt Cowan; 07-15-2013 at 12:02 AM.

+ 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. [SOLVED] Print lines to a text file based on change in cell contents
    By cthreepo986 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2013, 09:53 AM
  2. [SOLVED] Macro to highlight a cell if greater
    By ISUCyclones in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2012, 04:17 PM
  3. Macro to Insert Row if Cell is less than and next cell is greater than or equal to
    By jennifer.l.dean in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2009, 08:35 AM
  4. Replies: 4
    Last Post: 08-22-2006, 12:55 PM
  5. [SOLVED] Importing txt csv files into Excel greater than 65k lines
    By strippier in forum Excel General
    Replies: 1
    Last Post: 04-20-2005, 02:06 PM

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