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:
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,215,308
Messages
6,124,178
Members
449,146
Latest member
el_gazar

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