Finding largest instance of consecutive prefix spaces in a worksheet

lmoseley7

Board Regular
Joined
Jul 9, 2013
Messages
151
I'm copying a PeopleSoft department tree into Excel. For those unfamiliar, it is a grouping of departments similar to a file structure where certain departments roll up into other nodes (folders) that all eventually roll up to the ultimate parent node (folder). When pasting this into Excel, the levels I see in PeopleSoft are now denoted by preceeding spaces to indicate the former roll up structure. In the past I have found the largest number of preceeding spaces and starting with that number, used find and replace to replace the spaces with commas and then used text to columns to create the separation between levels through columns. I'd like to automate this with a macro.

What I envision is searching for the largest consecutive number of spaces and then working from that number down to 2, find and replace each with commas. Alternatively, I guess we could start with a number, say 10 for instance, and test for 10 spaces, then 9, etc. until we find the number and then use that to work through the find and replace code. I'm sure I could write something very clunky that would ultimately work, but I was hoping someone here might be able to offer a suggestion of how to make this happen in an efficient manner, both from a code and a coding perspective.

Thanks in advance for the help.
 
Thanks again for your help and explanation. I will study this code and try to find other ways I can use it as well.
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,215,239
Messages
6,123,817
Members
449,127
Latest member
Cyko

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