create one space amongs digits,letters and symbols

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
hello
I need making macro to make one space among numbers , letters and symbols let's take letters BS (always I have two letters in the beginning). it should make one space after two letters(BS ,FS,TQ.....)
about two numbers and letters R always I have two numbers and followed by letter R should not be space between each other of them like this (1200R20)
as to any letters contain (PR) and precede always two numbers should not be space between each other of them like this (18PR) and should be space where precede it (1200R20) and make one space after two numbers and letter R (G580) and make one space before the three letters(JAP,THI ,IND)
so based on item 2 should be like this BS 1200R20 18PR G580 JAP
as to items contain letter C the space should be after this letter and if there is no two numbers and letter R always like 18pr then should move to the next letter or number like BS 195R14C 613 JAP
as to stars BS 2400R25** VRLS JAP should make one space after stars
last thing if there are items contain hyphen"-" then should be delete it. the result in column B. when you see *** this is the short japan contains three letters J,A,P. the problem form tool XL2BB
I know there are many cases . this make things are complicated . if this is not clear just inform me
Bridgestone Sales Report 11 Nov 2021.xlsx
AB
1SIZE RESULT
2BS1200 R20 18PR G580JAPBS 1200R20 18PR G580 JAP
3BS 1200 R20 18PR G580 THIBS 1200R20 18PR G580 THI
4BS 1200 R20 18PRM802 THIBS 1200R20 18P RM802 THI
5BS 1200 R24 G582 JAPBS 1200R24 G582 JAP
6BS13 R22.5 R187JAPBS 13R22.5 R187 JAP
7BS 1400R20VSJ TCF JAPBS 1400R20 VSJ TCF JAP
8BS 155R12C R623 INDBS 155R12C R623 IND
9BS 175/70R14 EP150 THIBS 175/70R14 EP150 THI
10BS 175/70R14 MY02 THIBS 175/70R14 MY02 THI
11BS 185/65R14 EP150 INDBS 185/65R14 EP150 IND
12BS 185/65R14 TEC THIBS 185/65R14 TEC THI
13BS 185/65R15 T005 INDBS 185/65R15 T005 IND
14FS 195/60 R15 EP150THIFS 195/60R15 EP150 THI
15BS 195/65R15 EP15 JAPBS 195/65R15 EP15 JAP
16BS 195R14C 613 JAPBS 195R14C 613 JAP
17BS 195R15C R623 THIBS 195R15C R623 THI
18TQ 205/60R16 T001 JAPTQ 205/60R16 T001 JAP
19BS 205/70R15C R623 THIBS 205/70R15C R623 THI
20BS 215/55 R17 MY-02 THIBS 215/55R17 MY-02 THI
21LG 215/70R15C R623 THILG 215/70R15C R623 THI
22BS 225/70R15C R623 JAPBS 225/70R15C R623 JAP
23BS225/70R16 H005 THIBS 225/70R16 H005 THI
24BS 235/60R16 T01 JAPBS 235/60R16 T01 JAP
25BS 245/45R17 T05A JAPBS 245/45R17 T05A JAP
26BS 255/70R15C D840 THIBS 255/70R15C D840 THI
27BS 265/65R17 D840 JAPBS 265/65R17 D840 JAP
28BS 275/65R18 AL01 JAPBS 275/65R18 AL01 JAP
29BS 285/60R18 DHPS JAPBS 285/60R18 DHPS JAP
30BS 285/65R17 R683 JAPBS 285/65R17 R683 JAP
31BS 315/80R22.5 R152 JAPBS 315/80R22.5 R152 JAP
32BS 315/80R22.5 R184 JAPBS 315/80R22.5 R184 JAP
33BS 315/80R22.5 R184 THIBS 315/80R22.5 R184 THI
34BS 315/80R22.5-18PR G580 JAPBS 315/80R22.5 18PR G580 JAP
35BS 315/80R22.5-18PR G582 THIBS 315/80R22.5 18PR G582 THI
36BS 385/65 R22.5 R164 JAPBS 385/65R22.5 R164 JAP
37BS 385/65 R22.5 R164 THIBS 385/65R22.5 R164 THI
38BS 445/65R22.5 R164 JAPBS 445/65R22.5 R164 JAP
39BS 750R16R230 TCF JAPBS 750R16R230 TCF JAP
40BS 750R16 VSJ TCF JAPBS 750R16 VSJ TCF JAP
41DT 1200R24 DA53 THIDT 1200R24 DA53 THI
42DT 315/80R22.5 DS50 THIDT 315/80R22.5 DS50 THI
43DT 385/65R22.5 DT40 THIDT 385/65R22.5 DT40 THI
44BS 2400R25**VRLS JAPBS 2400R25** VRLS JAP
45BS29.5R25** VKTINDBS 29.5R25** VKT IND
46BS1600-2528PR RLS INDBS 1600-25 28PR RLS IND
Sheet1
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I need making macro to make one space among numbers , letters and symbols let's take letters BS (always I have two letters in the beginning). it should make one space after two letters(BS ,FS,TQ.....)
about two numbers and letters R always I have two numbers and followed by letter R should not be space between each other of them like this (1200R20)
as to any letters contain (PR) and precede always two numbers should not be space between each other of them like this (18PR) and should be space where precede it (1200R20) and make one space after two numbers and letter R (G580) and make one space before the three letters(***,THI ,IND)
so based on item 2 should be like this BS 1200R20 18PR G580 ***
as to items contain letter C the space should be after this letter and if there is no two numbers and letter R always like 18pr then should move to the next letter or number like BS 195R14C 613 ***
as to stars BS 2400R25** VRLS *** should make one space after stars
last thing if there are items contain hyphen"-" then should be delete it. the result in column B. when you see *** this is the short japan contains three letters J,A,P. the problem form tool XL2BB
I know there are many cases . this make things are complicated . if this is not clear just inform me
Hi @abdo meghari this could possibly be the right job for Regular Expressions if there is any kind of "logic" behind your text data.

Let's say your data can be expressed as follows:
<(exactly) two letters><one or zero space><at least two, but no more than three digits><one or zero slash signs><two or more digits><letter "R"><two digits><one or zero space><single letter><three digits><one or zero space><three letters>

This could make up following Regular Expression:
[A-Za-z]{2} ?/d{2,3}//?/d{2,}R/d/d ?[A-Za-z]/d/d/d ?[A-Za-z]{3}

If your data has this or any other kind of logic, it can be easily processed with VBA and Regular Expressions.

But, before I start over to write some code I'll need a little more information about your data.
So, could you express your data in the way I mentioned above?
 
Upvote 0
thanks for guide me the right way to express that ,but I thought my picture is clear . actually your way as programmer is very difficult for me.
but I do my best . I write my requirements based on your way . if you need more just tell me .

< two letters><one space><at least from three or more digits (without slash and symbols ) & letter(R)>< three or more(digits,letters)><one space>three or more letters> or < two letters><one space>< three digits or more & slash & two or more digits & letter(R) & two or more digits or letters><one space>< three or more(digits,letters)<one space> <three digits or more >or< two letters><one space><at least from three or more digits & two or more symbols & letter(R) & two or more digits or letters ><one space>< three or more(digits,letters)>< one space><three letters>
I hope this help
 
Upvote 0
In your sample results ..
- In cell B4, why is there a space between the 'P' and the 'R' when there isn't in B2 and B3?
- In cell B41, why is there three spaces before the DA53?
- In cells B20 and B46, why are there hyphens when you said they should be deleted?

Also, tell us about the two ** characters in rows 44 and 45
 
Upvote 0
@Peter_SSs I admit to issue this thread badly way . there are many mistakes and unclear
my apologies ?
- In cell B4, why is there a space between the 'P' and the 'R' when there isn't in B2 and B3?
sorry ! should not be space between P and R should be like B2,B3
- In cell B41, why is there three spaces before the DA53?
also this is wrong should be one space , but when I use copy & paste forgot correcting it
- In cells B20 and B46, why are there hyphens when you said they should be deleted?

this is very complicated . I had to explain clearly . what I meant delete just locates before two digits and letters PR as in row 34,35 before 18PR
always delete before two digits and two letters.
Also, tell us about the two ** characters in rows 44 and 45
this is the symbol (stars) is existed in some tires sizes
 
Upvote 0
@Peter_SSs maybe you have alternitive in your mind is close to my requirements. to understand the aim of make equel space among the letters and digits .

this report issue by differnt PC and I have report in my PC . I pull the values after matching between two reports by another macro . but the problem is different in the spaces among items between two reports and the macro will not pull the values because of thi problem . my real items about 1500 items if I do manually then it takes more time and exposed for mistakes like press twice or three spaces, but the macro correct any errors for spaces .

actually I don't complain , but maybe you can work for specific digits or lettres and ignore the others by split the macro for each specific digits or letters and issue new thread for each part for this complicated thread
thanks for your time .
 
Upvote 0
@Peter_SSs maybe you have alternitive in your mind
No I don't because I do not understand the "rules" for how the desired format is arrived at. I think at least part of the problem is that it appears that English is not your main language so what is making sense to you is not making sense to me.
 
Upvote 0
"...to understand the aim of make equel space among the letters and digits .

this report issue by differnt PC and I have report in my PC . I pull the values after matching between two reports by another macro . but the problem is different in the spaces among items between two reports..."

If the objective is to match items from the two reports, and the problem is the different placement of spaces, why not delete all the spaces from both reports and then run your matching macro?

Happy Holidays!

Tony
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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