Hopefully a simple find and replace VBA script

IronMountain

New Member
Joined
Mar 14, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have the following data (before.png):

I would like to have a VBA script which runs through column A looking for a carriage return.
Upon finding one, it copies that entire row but only with everything PRIOR to the carriage return - it will make a new row for each iteration. It will then add a column which states NEW or ORIG for whether the row is new (as it contained a carriage return) or ORIG as it did not.

see after.png for results required.

I'm losing my hair on this one!!!
 

Attachments

  • before.PNG
    before.PNG
    4 KB · Views: 26
  • after.PNG
    after.PNG
    7.3 KB · Views: 25

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you're pulling your hair out, you must have already written some code but it's not working for you. Reviewing that would be a good place to start. Or you can consider that the approach would be along the lines of:
- find the last row with data (e.g. 100)
- create a loop that will go from 100 to first non-header row
- test for each A column row for Chr(10) using Instr function
- if found, break the cell value into an array using Split function. If it has 3 elements then you want to insert 3 rows, or is this not possible?
- insert as many rows as there are array elements;
- - write array(0) to first inserted row, copy B:F to inserted row, write NEW to column G
- - write array(1) to next inserted row & rest as before
- - repeat as necessary
- loop then moves to the next row number & repeats

That may be a bit simplified. I usually uncover aspects not considered when describing an idea such as this.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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