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:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How about
Code:
Sub manvit()
   With Range("A2", Range("B" & Rows.Count).End(xlUp))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
End Sub
 
Upvote 0
Hey fluff,
this command .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
gives me "run time error 1004, no cells were found "
 
Upvote 0
please explain me the code so that i can understand why you the code this way. the code runs perfectly for the first time. second time when i re run it, it gives me an error. why is that ? is it becoz they were no more cells to be repeated ?
 
Upvote 0
In that case you don't have any empty cells in columns A or B
What is in those cells?
 
Upvote 0
Hey fluff,
this command .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
gives me "run time error 1004, no cells were found "
Are those "blank" cells truly blank (absolutely nothing in them) or are there either spaces or formulas in them?
 
Upvote 0
it runs perfectly when i run them for the first time. but my platform( tool which handles data formatting) which runs this macro may run it again and then it gives me an error saying no empty cells found. can we make the error stop somehow? i mean if its error, ignore somehow ?
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,168
Members
452,615
Latest member
bogeys2birdies

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