keith05281967
Board Regular
- Joined
- May 6, 2011
- Messages
- 68
Greetings All,
I posted this question yesterday but failed to mention that i'm looking for a vba solution. I did get some great answers but they were in the form of worksheet functions =LEFT(A1,LEN(A1)-2)&REPT(" ",3-(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))&RIGHT(A1,2)
I have cells with data like this: "Houston TX " or "Phoenix AZ " but occasionally it comes in like "AustinTX " with no spacing.
In order to pass the database test these cells should have at least 3 spaces between the city and the 2 digit state. I think the logic to make this work is to start from the far right of the cell, remove any trailing spaces, then move 2 spaces left so the focus is to the immediate left of the 2 digit TX state abbv. then going right to left count the number of spaces. If < 3 spaces then add 3 spaces.
It would loop thru a column of data doing this.
Can this be done in vba code?
Excel '07
thanks,
Keith
<!-- / message -->
I posted this question yesterday but failed to mention that i'm looking for a vba solution. I did get some great answers but they were in the form of worksheet functions =LEFT(A1,LEN(A1)-2)&REPT(" ",3-(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))&RIGHT(A1,2)
I have cells with data like this: "Houston TX " or "Phoenix AZ " but occasionally it comes in like "AustinTX " with no spacing.
In order to pass the database test these cells should have at least 3 spaces between the city and the 2 digit state. I think the logic to make this work is to start from the far right of the cell, remove any trailing spaces, then move 2 spaces left so the focus is to the immediate left of the 2 digit TX state abbv. then going right to left count the number of spaces. If < 3 spaces then add 3 spaces.
It would loop thru a column of data doing this.
Can this be done in vba code?
Excel '07
thanks,
Keith
<!-- / message -->