+ Reply to Thread
Results 1 to 2 of 2

VBA Conditional Sequential Numbering

  1. #1
    Registered User
    Join Date
    07-29-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    51

    VBA Conditional Sequential Numbering

    I have a worksheet that has a formula =IF($B13>0, $A12+1, "") in cell A13. The formula is copied down in column A. Cell A12 has a value of 1. What this will do is to sequentially number each successive row in column A when the value of the corresponding cell in column B is greater than 0.

    This works great, except for when I want to print. Since I have this formula copied down column A all the way to row 717, the print area is set to print the selection containing all of the formulas, even if the cells are blank.

    I tried to enter the formula into the conditional formatting "Formula Is", but it did not put a numerical value into the cell.

    I'm very new to VBA, but I think that what I need is a VBA code that will automatically enter a sequential number into column A if the value in column B is not blank (either a number, text, or both), otherwise to leave column A blank.

    Lastly, is there a way to make this macro run automatically so that I don't have to click on a button?

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA Conditional Sequential Numbering

    No need for VBA.

    When you create a Print Area a Named Range is created - you can configure the Named Range to be Dynamic such that it expands and contracts as necessary.

    Mike Girvin has a demo up on You Tube of this: http://www.youtube.com/watch?v=aLkNIVMnAZY

    In your case (unlike the demo) your named range will be determined by the location of the last numeric value in Column A
    (we don't use COUNTA because this will see the formulae Nulls in A as non-blank)

    If we assume:

    a) sheet being printed in Sheet1
    b) top left cell to be printed is always A1
    c) last column included in the Print Area is always D
    then the Print Area Named Range can be made dynamic by modifying the RefersTo formula to:

    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)

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