+ Reply to Thread
Results 1 to 11 of 11

How to populate blank cells with sequence until nonblank cell is encountered?

Hybrid View

Jasonhouse How to populate blank cells... 03-22-2014, 04:42 PM
Ron Coderre Re: How to populate blank... 03-22-2014, 04:53 PM
Jasonhouse Re: How to populate blank... 03-22-2014, 05:03 PM
Ron Coderre Re: How to populate blank... 03-22-2014, 05:12 PM
Jasonhouse Re: How to populate blank... 03-22-2014, 05:20 PM
Ron Coderre Re: How to populate blank... 03-22-2014, 05:30 PM
Jasonhouse Re: How to populate blank... 03-22-2014, 06:10 PM
Jasonhouse Re: How to populate blank... 03-22-2014, 06:20 PM
Jasonhouse Re: How to populate blank... 03-22-2014, 09:22 PM
Ron Coderre Re: How to populate blank... 03-22-2014, 10:08 PM
Jasonhouse Re: How to populate blank... 03-23-2014, 08:47 AM
  1. #1
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    How to populate blank cells with sequence until nonblank cell is encountered?

    I've been looking around at the various sites, trying to find a code that either does this, or that I could easily adapt to my needs... But with no luck so far.

    I presume this is fairly simple to do, since it's certainly easy enough to do manually by filling in a couple of rows and dragging them down, but I need it to be performed in a macro that I can run before other macros run.


    What I need specifically is for the macro to go to G1 and insert the number .01... Then go to G2 and insert .02... Then G3 and insert .03... And repeat this until it finds the first non-blank cell ( row number this occurs at varies), at which point it ends and does nothing to that populated cell or any other cell in the column thereafter (including other blanks farther down).

    This all needs to be done in Arial, 10pt, white.


    Please help!
    Last edited by Jasonhouse; 03-27-2014 at 07:44 PM.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Try this code in a general module:
    Sub BuildSeq()
    Dim rng As Range
    
    Set rng = [G1]
    rng.Value = 0.01
    Set rng = Range(rng, rng.End(xlDown).Offset(rowOffset:=-1))
    rng.DataSeries Type:=xlLinear, Step:=0.01
    End Sub
    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Yeah, but how to end it at the first populated cell? That script populates every cell in G, whether it's already populated or not.

    I figured I would need the script to include a 'Do Until' which basically tells it to do what you just wrote up, but then stops it when it encounters a populated cell. But I don't know, because I'm a complete noob at macros.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Your instructions were to run the sequence from G1 until a populated cell was encountered.

    Absent a posted sample file or sample data, here's what I used:
    • G1:G11 are blank
    • G12 contains text
    • I ran the macro...It entered a sequence from 0.01 through 0.11 in G1:G11

    Can you post a sample file that exhibits your scenario?

  5. #5
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Wait, it worked fine! I wasn't paying attention and ran it on a list that had all of G blank from a previous macro failure.


    But how to make the newly generated numbers display in white though?
    Last edited by Jasonhouse; 03-22-2014 at 05:22 PM.

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    White text on white cells? Really?
    Can you share ALL of the specifics so we can try to do this in one go?

  7. #7
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    ^yes white, so that it is not visible.


    Example.xls
    (Your macro is loaded, but hasn't been run)

    What it's doing is exactly what I need it to do, it just needs to be in white.

  8. #8
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    I figured out the white part...

    Or at least it's working. Probably not the most elegant way to do it.

    Since there will never be any other numbers in the column that are less than 1...
    Sub BuildSeq()
    Dim rng As Range
    
    Set rng = [G1]
    rng.Value = 0.01
    Set rng = Range(rng, rng.End(xlDown).Offset(rowOffset:=-1))
    rng.DataSeries Type:=xlLinear, Step:=0.01
    Columns("G:G").Select
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
            Formula1:="=1"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Font
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    End Sub

  9. #9
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Problem... Once this macro is run, it is correctly filling in the blank cells with the correct sequence, until it encounters the first populated cell.

    But then then once it has been run once, if it is run again, it is rewriting over other cells which already have numbers in them. It needs to be so that once it is run and has filled in the blank cells, if it is run again, it will sense that G1 is already populated and won't do anything.

    Seems like before rng.Value is set to .01, it needs an if/then to check whether the cell already has content, and if it does then nothing happens. (and it also doesn't throw an error code)

  10. #10
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Try this variation:
    Sub BuildSeq()
    Dim rng As Range
    
    Set rng = [G1]
    If rng.Value = "" Then
        rng.Value = 0.01
        Set rng = Range(rng, rng.End(xlDown).Offset(rowOffset:=-1))
        With rng
            .DataSeries Type:=xlLinear, Step:=0.01
            .FormatConditions.Delete
            .FormatConditions.Add _
                Type:=xlCellValue, _
                Operator:=xlLess, _
                Formula1:="=1"
            With .FormatConditions(1)
                .SetFirstPriority
                .Font.ThemeColor = xlThemeColorDark1
                .Font.TintAndShade = 0
                .StopIfTrue = False
            End With
        End With
    End If
    End Sub
    Does that help?

  11. #11
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How to populate blank cells with sequence until nonblank cell is encountered?

    Yes! Very good man. Most helpful, thank you!

    Can't wait til I understand this stuff better.

+ 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. Replies: 2
    Last Post: 04-29-2013, 04:20 AM
  2. [SOLVED] If cell is not blank, assign next number in sequence
    By dylaughin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2012, 03:57 PM
  3. Replies: 2
    Last Post: 12-22-2011, 07:05 PM
  4. [SOLVED] How do I find the minimum NONBLANK value in a sequence of cells?
    By codeslinger in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-02-2005, 06:20 PM
  5. [SOLVED] How do I find the minimum NONBLANK value in a sequence of cells?
    By codeslinger in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-02-2005, 06:17 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