Fill empty cells in a row between two value containing cells

likexl

New Member
Joined
May 7, 2011
Messages
18
Hello,

How one can achive solution in the following situation:

ID
STATUS
DAY1
DAY2
Day3
Day4
DAy5
H1
PASSIVE
100
100
100
H2
ACTIVE
100
500
H1
ACTIVE
100
500
200
H3
ACTIVE
100
200
500
H4
ACTIVE
100
200
500

<tbody>
</tbody>










After executing vba code following is expected:

ID
STATUS
DAY1
DAY2
Day3
Day4
DAy5
H1
PASSIVE
100
100
100
H2
ACTIVE
100
100
100
100
500
H1
ACTIVE
100
100
500
500
200
H3
ACTIVE
100
200
200
200
500
H4
ACTIVE
100
200
500

<tbody>
</tbody>











Id can be duplicate, but id active will be unique.
Value in the empty cell filled will based on previous.

Thanks.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
this should get you started

Code:
Sub likexl()
'count columns to proceed
lcol = Cells(1, Columns.Count).End(xlToLeft).Column
'loop through rows
For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
 'loop column in each row
  For j = 1 To lcol
   'check if last cell has been reached
   If Cells(i, j).Column <> lcol Then
    'copy values to empty cells
    If Cells(i, j + 1) = "" Then Cells(i, j + 1) = Cells(i, j)
   End If
  Next j
Next i
End Sub
 
Upvote 0
Solution
Dear Hippiehacker,

Thank u very much for your reply.

this should get you started

In most cases "Investment of time solves the stuff" - sometimes not!

so, I also got one working solution with - try n error. I am giving it here so that one can modify according to needs :

Code:
Dim count As Long
                    count = dayin + 3
                    Do
                    count = count - 1
                    Loop Until ActiveCell.Offset(0, count - 1).Value <> ""
                    
                    count = count - 1
                    fillvalue = ActiveCell.Offset(0, count).Value
                    
                    Do
                    ActiveCell.Offset(0, count + 1).Value = fillvalue
                    count = count + 1
                    Loop Until ActiveCell.Offset(0, count + 1).Value <> ""

This will fill between two values, this can be repeated for other gaps as well.
Thanks again.
:)
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,360
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top