Andyatwork
Board Regular
- Joined
- Mar 29, 2010
- Messages
- 94
Hello all,
I am having a problem passing a text string (from a csv file pulled into excel 07) to an array and using split to pull out some relevant information.
The string is always of the format; Closure : 1234 - blah blah blah where '1234' is a variable number sandwiched between a colon and a hyphen, and 'blah blah blah' is a free text field populated by a user at some earlier point in time.
I want to split the string on the Colon, discard the first element (Closure), pass the second element to a new array, split the new array on the Hyphen and push the resulting new first element (the number) to a range, and the second element (the free text string) to a second range.
My problem is that after doing the first split on the colon my first array seems to think it only has 2 elements; "Closure" and "1234". Everything from the hyphen on goes poof so of course the second split does nothing. I've confirmed this with debug.print.
I have read that hyphens can sometimes be represented by ascii chr(45) and chr(150) but replacing "-" with "chr(45)" or "chr(150)" as the delimiter optional in SPLIT made no difference.
Sample string to be split
Closure: 616 - Rebatch Sale 30/06/2014
End result should be 616 in every cell of a predefined range and "Rebatch Sale 30/06/2014" in every cell of a second predefined range.
Has anyone got any tips on how I can salvage the free text field from this string? VBA just isn't seeing the hyphen or registering the existence of anything past it.
I think I need to identify the hyphen and replace it with something that VBA can see, and hopefully the invisibility cloak will go away and SPLIT should work again.
Any guidance or pointing out how i'm using split and array incorrectly, would be greatfully received.
Regards,
Andy
I am having a problem passing a text string (from a csv file pulled into excel 07) to an array and using split to pull out some relevant information.
The string is always of the format; Closure : 1234 - blah blah blah where '1234' is a variable number sandwiched between a colon and a hyphen, and 'blah blah blah' is a free text field populated by a user at some earlier point in time.
I want to split the string on the Colon, discard the first element (Closure), pass the second element to a new array, split the new array on the Hyphen and push the resulting new first element (the number) to a range, and the second element (the free text string) to a second range.
My problem is that after doing the first split on the colon my first array seems to think it only has 2 elements; "Closure" and "1234". Everything from the hyphen on goes poof so of course the second split does nothing. I've confirmed this with debug.print.
I have read that hyphens can sometimes be represented by ascii chr(45) and chr(150) but replacing "-" with "chr(45)" or "chr(150)" as the delimiter optional in SPLIT made no difference.
Sample string to be split
Closure: 616 - Rebatch Sale 30/06/2014
End result should be 616 in every cell of a predefined range and "Rebatch Sale 30/06/2014" in every cell of a second predefined range.
Has anyone got any tips on how I can salvage the free text field from this string? VBA just isn't seeing the hyphen or registering the existence of anything past it.
I think I need to identify the hyphen and replace it with something that VBA can see, and hopefully the invisibility cloak will go away and SPLIT should work again.
Any guidance or pointing out how i'm using split and array incorrectly, would be greatfully received.
Regards,
Andy