+ Reply to Thread
Results 1 to 10 of 10

Fill in blanks with a value using a Macro

  1. #1
    Forum Contributor
    Join Date
    08-15-2006
    Location
    USA
    MS-Off Ver
    Office 365, 64 bit
    Posts
    362

    Fill in blanks with a value using a Macro

    In the attached file, there is a column called status. The column is normally up to 3k rows. However, they only update the yellow and red status and leave the green blank. I want a macro that will scan the column and enter "green" in the empty cells for that column... see attached...
    Attached Files Attached Files

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Fill in blanks with a value using a Macro

    Try this.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    12-06-2016
    Location
    India
    MS-Off Ver
    2007
    Posts
    72

    Re: Fill in blanks with a value using a Macro

    Hi,

    Try this

    Sub tst()
    Dim myLastRow AS Long
    ActiveSheet.UsedRange
    myLastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row

    For I = 1 To myLastRow

    If Range("B" & I) = "" Then
    Range("B" & I).Interior.Color = RGB(0, 255, 0)
    End If

    Next I


    End Sub

  4. #4
    Forum Contributor
    Join Date
    08-15-2006
    Location
    USA
    MS-Off Ver
    Office 365, 64 bit
    Posts
    362

    Re: Fill in blanks with a value using a Macro

    Hi bakerman2 ---I get a an error: variable not defined (sn =). In my file, the column is BQ where BQ3 is the header and BQ4 is the row under it... your code works well in my sample file but not in my actual file... what am I doing wrong?

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Fill in blanks with a value using a Macro

    Both of the above solutions use a for next loop which could prove to be slow for a large amount of data.

    Why not put a formula into an empty column

    And Paste the values into your target column?


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 02-10-2017 at 03:28 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  6. #6
    Forum Contributor
    Join Date
    08-15-2006
    Location
    USA
    MS-Off Ver
    Office 365, 64 bit
    Posts
    362

    Re: Fill in blanks with a value using a Macro

    Mehmetcik: How can I make this work for column where BQ3 is the header and BQ4 is the row under it?

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Fill in blanks with a value using a Macro

    All you need to change to different column is this line

    With .Range("BQ3:BQ" & .Cells(Rows.Count, "BQ").End(xlUp).Row)

    FYI: I have already change the column
    Attached Files Attached Files
    Last edited by AB33; 02-10-2017 at 04:54 PM.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Fill in blanks with a value using a Macro

    @mehmetcik

    Both of the above solutions use a for next loop which could prove to be slow for a large amount of data.
    True if you perform the loop on the worksheet. But as you might have noticed my loop is performed in memory and the resulting array is written to worksheet in one go so speed loss will be minimal.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Fill in blanks with a value using a Macro

    Please Login or Register  to view this content.
    Last edited by jindon; 02-10-2017 at 09:56 PM.

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Fill in blanks with a value using a Macro

    I do not understand your Question.

    Two possible meanings.

    1. Your Data Column is now Column BQ not Column C as previously stated.

    Please Login or Register  to view this content.
    2. Use Column BQ as the helper Column

    Please Login or Register  to view this content.
    3. On reflection there is a faster method.

    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)

Similar Threads

  1. [SOLVED] Fill in blanks macro is not working properly
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2017, 11:45 AM
  2. Macro to fill in blanks with previous data
    By macronewbie9981 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2016, 01:56 PM
  3. Fill in the Blanks - VBA
    By hillmas83 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-18-2015, 10:49 AM
  4. Macro to fill blanks with listed data
    By jackubu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2013, 02:48 AM
  5. Macro to fill in blanks with the data of the cell above
    By Fugazi_Dent in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2013, 06:20 AM
  6. [SOLVED] Macro to fill in missing blanks with data in a column
    By robertguy in forum Excel General
    Replies: 6
    Last Post: 10-19-2012, 02:49 AM
  7. fill in the blanks
    By JAMES GABEL in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-24-2007, 04:59 AM

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