+ Reply to Thread
Results 1 to 8 of 8

how to change list of empty cells with a value ?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-06-2011
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    3

    how to change list of empty cells with a value ?

    [Excel2003] If is not so easy to input repeated value to a different cell location.
    And so much moving cursor and pasting to do the job! Is there any solution ?

    if this is the selection of cells, and "-" means empty, new value to be replace = "x
    "
    a
    -
    -
    b
    c
    -

    becomes

    a
    x
    x
    b
    c
    x

    how to code it using the current region to replace current empty cell with "x" ?

    thanks for helping hands! I really need this to speed up my work!
    Last edited by johan3000; 01-07-2011 at 12:22 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to change list of empty cells with a value ?

    You'll have to modify this a bit to suit your workbook but try this:
    Sub replaceBlanks()
        For Each loopCell In Worksheets("Sheet1").Range("A1:A6")
            If loopCell.Value = "" Then loopCell.Value = "x"
        Next loopCell
    End Sub
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    01-06-2011
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: how to change list of empty cells with a value ?

    Quote Originally Posted by Mordred View Post
    You'll have to modify this a bit to suit your workbook but try this:
    Sub replaceBlanks()
        For Each loopCell In Worksheets("Sheet1").Range("A1:A6")
            If loopCell.Value = "" Then loopCell.Value = "x"
        Next loopCell
    End Sub


    thanks bro Mordred,

    Let the user decided which region to modify!
    but why this one is not working ?

    For Each c In ActiveCell.CurrentRegion.Cells
            If c.Value="" Then c.Value = "X"
    Next
    Last edited by teylyn; 01-06-2011 at 11:22 PM. Reason: added code tags

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: how to change list of empty cells with a value ?

    Please put all code in code tags. I'll do it for you now, but remember it next time, please.

    For a VBA free approach, select the range of cells, hit F5, click Special, tick Blanks, hit OK, type "x", hold down Ctrl and hit enter.

    cheers,

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to change list of empty cells with a value ?

    Mayhap teylyn's approach is better because my approach does not let the user decide which range to select.

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to change list of empty cells with a value ?

    As far as this goes:
    For Each c In ActiveCell.CurrentRegion.Cells
            If c.Value="" Then c.Value = "X"
    Next
    It will replace blank cells in a region with x. For instance, if you only want to have a range down column A to run the code but range("C5") is selected then all cells from range A1 to C5 will be referenced and then all the empty cells will be replace with x (sorry for the run-on).

  7. #7
    Registered User
    Join Date
    01-06-2011
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: how to change list of empty cells with a value ?

    thanks Teyln and Mordred.

    your solution is excellent... like knife cutting through the butter...

    if someone prefer in code (TESTED and worked),

    Sub text2blank()
    ' This macro :
    ' replace selection with xStr for any blank value
        xStr = Application.InputBox( _
        prompt:="What Text to be inserted to Blank : ", Type:=2)
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = xStr
    End Sub
    I love this forum....
    Last edited by johan3000; 01-07-2011 at 12:24 AM.

  8. #8
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: how to change list of empty cells with a value ?

    Thanks for the feedback, Johan. Stick around. You'll love it even more.

    Why not try and answer some questions?

    cheers,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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