+ Reply to Thread
Results 1 to 10 of 10

macro to fill blank cells with location

Hybrid View

  1. #1
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro to fill blank cells with location

    Hi kellen

    Try this
    Option Explicit
    Public Sub test()
        Dim LastRow As Long
        Dim Rng As Range
        Dim fCell As Range
        LastRow = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, _
                             SearchDirection:=xlPrevious).Row
        Set Rng = Range("A3:A" & LastRow)
        For Each fCell In Rng
            If Not fCell.Offset(0, 1) = "" And fCell = "" Then
                fCell.Value = fCell.Offset(-1, 0)
            End If
        Next fCell
    End Sub
    Hope this helps.

    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  2. #2
    Registered User
    Join Date
    08-23-2010
    Location
    Victoria, BC
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: macro to fill blank cells with location

    Great! Thanks John, this works perfectly.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: macro to fill blank cells with location

    JB, that won't work correctly for a multi-area range.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro to fill blank cells with location

    Hi kellen
    Glad it works for you. If you're satisfied, please mark your post as solved. Click the scales if you feel it appropriate.

    John

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to fill blank cells with location

    Quote Originally Posted by shg View Post
    JB, that won't work correctly for a multi-area range.
    It won't? It seemed to work fine for my test which was 3 separate areas, as per the OP's example. Can you reference an example of what you mean? I used a formula in the macro that takes into account the fact the a row might be blank, it skips those...

    I like this approach merely for the elimination of looping row by row, the formula does the evaluation for you all at once.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: macro to fill blank cells with location

    See attached.
    Attached Files Attached Files

+ 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