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 .

DateordernumName
1/2/2019A23423Alex
1/2/2019B54534John
5/2/2019E454Joe
4/2/2019C64354Ruby

<tbody>
</tbody>

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.

DateordernumName
1/2/2019A23423Alex
1/2/2019A23423
1/2/2019A23423
1/2/2019
A23423
1/2/2019B54534John
1/2/2019B54534
1/2/2019B54534
5/2/2019E454Joe
5/2/2019
E454
4/2/2019C64354Ruby

<tbody>
</tbody>

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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
Sorry, I don't understand
 
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,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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