Repeat the value until the occurrence/presence of a value using macros

manvit

New Member
Joined
Oct 31, 2018
Messages
19
Hi All :),
My input is like this .

[TABLE="width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]ordernum[/TD]
[TD]Name[/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]A23423[/TD]
[TD]Alex[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]B54534[/TD]
[TD]John[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5/2/2019[/TD]
[TD]E454[/TD]
[TD]Joe[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4/2/2019[/TD]
[TD]C64354[/TD]
[TD]Ruby[/TD]
[/TR]
</tbody>[/TABLE]

In this above excel sheet, i need to repeat the values in 1st and 2nd column until the occurrence of a new value.



i.e the output should be like this.

[TABLE="width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]ordernum[/TD]
[TD]Name[/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]A23423[/TD]
[TD]Alex[/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]A23423[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]A23423[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/2/2019
[/TD]
[TD]A23423[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]B54534[/TD]
[TD]John[/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]B54534[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/2/2019[/TD]
[TD]B54534[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5/2/2019[/TD]
[TD]E454[/TD]
[TD]Joe[/TD]
[/TR]
[TR]
[TD]5/2/2019
[/TD]
[TD]E454[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4/2/2019[/TD]
[TD]C64354[/TD]
[TD]Ruby[/TD]
[/TR]
</tbody>[/TABLE]

please NOTE: the change needs to only happen in column 1 and 2.

I am beginner in Macros, anybody help with code and its explanation would be much appreciated.


Thanks,
Manvit
 
Last edited:
Ok, I hadn't seen post#6 as we posted at the same time.
The code looks for all blank cells in cols A & B from row 2 to the last row with data in col B & then inserts a formula that returns the value in the cell above.
The code then converts the formula to a value.

Once you have run the code once, there will be no blank cells & that's why you get the error.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This will deal with the error if there are no blank cells
Code:
Sub manvit()
   On Error Resume Next
   With Range("A2", Range("B" & Rows.Count).End(xlUp))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
   On Error GoTo 0
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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