Count Spaces or Find 1st Letter

Tom@CPC

Board Regular
Joined
May 22, 2002
Messages
209
I have a dump of data in a worksheet that comes out of "SAP". It is great for a sales rep or a manager to look at because it is a pretty picture of their performance. It is useless as an analytic tool for analysts though. What I need to do is take one column of data from the dump and find the first non-space character. I say non-space character because the SAP application inserts hard spaces that provide indents for a VP to GM to Director to Manager to cost centre reporting hierarchy. The number of spaces indicating the level in the reporting hierarchy. This format is what is useless for analytics.

Any help with some code would be greatful.

There are approximately 350 entries that need to be cycled through. The first non-space character could be anywhere from the second (2nd) to the thirty-first (31st) character. The position of that character should be placed in the cell next to the entry.

For starters, what I've been unsuccessfuly dabbling at is for each cell in the range, look at the first character, and if it is code 160 (for the space) increase a counter by one and move right to the next character and continue increasing the counter until the first non-space is reached. The counter value for the spaces plus one for the non-space value should be returned to the cell beside the active cell. Eventually the Characters excluding those spaces would be entered into columns which will then provide me a rollup structure for these levels.

There will be a pattern for the levels within the hierarchy. For example, first character in position 2 would be a Senior VP, and all first characters in positions 8 thru 10 would be GM's and report to the Sr. VP. Entries whith first characters in position 11 thru 13 would be Directors and report to one of the GM's etc...

Any help would be welcome.

TIA

Tom
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I deal with alot of data out SAP into excel as well (although none of my SAP reports are every pretty). A couple things come to mind:

- try text to column on the column in question

-formulaicly, you want to use
=LEFT(TRIM(A1))
instead of
=LEFT(A1)

or
=LEFT(SUBSTITUTE(A1,CHAR(160),""))

by the way, my blanks are char(32)
 
Upvote 0
IML,

Thanks!

The second one worked well for extracting the letter, I then applied "find" to it to return the position. I had tried the left and trim functions but it wasn't working for me.

Regards,

Tom
 
Upvote 0
JRN,

I did use Clean to eliminate the hyperlink junk and the expand/contract arrows, but it did nothing for the junk spaces. Thanks for the input.

T
 
Upvote 0
On 2002-08-21 12:28, Tom@CPC wrote:
IML,

Thanks!

The second one worked well for extracting the letter, I then applied "find" to it to return the position. I had tried the left and trim functions but it wasn't working for me.

Regards,

Tom

glad it worked. If it just the positon you are after, you may be able to get away with

=LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(160),""))+1

as well. I misread your question a bit (as is usual for me).
 
Upvote 0
Not sure I understood your question properly, but the following would count how many leading spaces an entry has:

=SEARCH(LEFT(TRIM(A1),1),A1)-1

If you also have CHAR(160) before an entry, you could use instead:

=SEARCH(LEFT(TRIM(SUBSTITUTE(A1,CHAR(160),CHAR(32)),1),A1)-1
 
Upvote 0

Forum statistics

Threads
1,203,203
Messages
6,054,117
Members
444,703
Latest member
pinkyar23

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