Francisco Luiz Brum Pinto Francisco Luiz Brum Pinto - 3 months ago 9
C# Question

Excel Macro Loop between 2 columns and check for empty cell and add cell VBA or C#

enter image description here

Excel Macro Loop between 2 columns and check for empty cell and add cell VBA or C#
Thanks in Advance

Answer

It looks as though you place the value from C in the row above where it is found. So you can do this in VBA

finalRow=Cells(65000,1).end(xlup).row 'get me the last row with data in col a
for i = 4 to finalRow 'loop through those rows
    if not isempty(cells(i, 3)) and isempty(cells(i, 1)) then 'if something in c, but not an for same row then
        cells(i-1, 5) = cells(i, 3) 'put c value in col e (one row up)
        cells(i, 3) = "" 'set c value to nothing
    end if
next i