Find First Non-empty Cell & Paste To Preceding Cells

  • I need to find the first non-empty cell in a range and paste a constant value into the preceding cells.


    aa bb
    aa bb
    aa bb
    aa bb cc
    aa bb cc



    aa bb xx
    aa bb xx
    aa bb xx
    aa bb cc
    aa bb cc

  • Re: Find First Non-empty Cell And Paste A Value Into Preceding Cells


    Hi, and welcome to the OzGrid!


    I think you need to be a bit more explicit in your question:
    The first non-empty cell which way? rows-then-columns or vice versa?
    Preceding cells, how so?
    Do you want to do this once, in Excel? or as part of a bigger VBA project?


    Your example suggests that you just want to fill all the empty cells in the range with a constant.


    One way could be to use

    Code
    Range("A1:C6").SpecialCells(xlCellTypeBlanks).Select
  • Re: Find First Non-empty Cell And Paste A Value Into Preceding Cells


    Assuming your data is in Range A1:A5 the following macro will replace the blank cells with "cc"s


    aa bb
    aa bb
    aa bb
    aa bb cc
    aa bb cc



    Hope this helps.


    Thanks,
    Rennie

  • Re: Find First Non-empty Cell & Paste To Preceding Cells


    I have a sheet that is always layed out the same. Columns A through K with x amount of rows.


    I have a macro that I recorded and modified a little that does a few things to format the sheet correctly and autofills columns A and C.
    I need to find all of the blank cells in column K and fill it in with the value 'XXCXX'.


    Here is the code of the macro that I have so far


  • Re: Find First Non-empty Cell & Paste To Preceding Cells


    I added the following to the macro and it seems to have done the trick.
    Does anyone see any danger to this method?



    Code
    Columns("K:K").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.Replace What:="", Replacement:="XXCXX", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!