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:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]STATUS
[/TD]
[TD]DAY1
[/TD]
[TD]DAY2
[/TD]
[TD]Day3
[/TD]
[TD]Day4
[/TD]
[TD]DAy5
[/TD]
[/TR]
[TR]
[TD]H1
[/TD]
[TD]PASSIVE
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]H2
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]500
[/TD]
[/TR]
[TR]
[TD]H1
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD][/TD]
[TD]500
[/TD]
[TD][/TD]
[TD]200
[/TD]
[/TR]
[TR]
[TD]H3
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD]200
[/TD]
[TD][/TD]
[TD][/TD]
[TD]500
[/TD]
[/TR]
[TR]
[TD]H4
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD]200
[/TD]
[TD]500
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]










After executing vba code following is expected:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]STATUS
[/TD]
[TD]DAY1
[/TD]
[TD]DAY2
[/TD]
[TD]Day3
[/TD]
[TD]Day4
[/TD]
[TD]DAy5
[/TD]
[/TR]
[TR]
[TD]H1
[/TD]
[TD]PASSIVE
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]H2
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD]500
[/TD]
[/TR]
[TR]
[TD]H1
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD]100
[/TD]
[TD]500
[/TD]
[TD]500
[/TD]
[TD]200
[/TD]
[/TR]
[TR]
[TD]H3
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD]200
[/TD]
[TD]200
[/TD]
[TD]200
[/TD]
[TD]500
[/TD]
[/TR]
[TR]
[TD]H4
[/TD]
[TD]ACTIVE
[/TD]
[TD]100
[/TD]
[TD]200
[/TD]
[TD]500
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]











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

Thanks.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

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