Hi, I am new in the ways of VBA coding, and I have been mostly adapting recorded code. The most that I can do is to define variables, make relative references and simple loops xD
I am working with catalogs for cars and car parts. For one particular distributor, the only way of obtaining the full specs from the system is all altogether.
In this way, we need to separate the text manually, and this process is a quite time-consuming process (The texts are way longer than what is presented in the example).
Example 1, (let's say this text is pasted in cell A1):
Final result for Example 1:
Now the tricky part is that there is no marker distinguishing the titles from the text, some have ":" at the end, some not...
Also, although the titles appear always in the same order, if there is no information regarding one of these, it simply does not appear in the text.
Example 2 (Equal to example 1, but with no Front Axle information):
As there are no markers for the titles, I am thinking that the best is to set the titles as constants.
This way if more titles are introduced into the system, I can simply add them to the code, and add a number to the Integer:
Code start example:
Dim Const Title1 = "Engine size - Displacement - Engine capacity:"
Dim Const Title2 = "Body: SUV / TT Num. of Doors:"
Dim Const Title3 = "Wheelbase:"
Dim x As Integer
For x = 1 To 3
Having these constants defined, it would be possible to do the following:
Step 1 -Search for the first title in the code; If not found, search for title2; If found, paste it in the cell below;
Step 2 -Search for the following title; if found, paste the text contained between the first found title and the second found title, one cell down, one cell to the left; If not found, search the next title;
Step3 - Loop
And repeating this process untill all titles present in the original cell are separated below:
My question is if this is possible, or if there is a better way of doing it, I am searching for ideas.
Can someone advise if I am thinking well here?
I am working with catalogs for cars and car parts. For one particular distributor, the only way of obtaining the full specs from the system is all altogether.
In this way, we need to separate the text manually, and this process is a quite time-consuming process (The texts are way longer than what is presented in the example).
Example 1, (let's say this text is pasted in cell A1):
Engine size - Displacement - Engine capacity: 999 cm3 or 61 cu-in Body: SUV / TT Num. of Doors: 5 Wheelbase: 267.4 cm or 105.28 inches Length: 434.1 cm or 170.91 inches Width: 180.4 cm or 71.02 inches Height: 169.3 cm or 66.65 inches Front Axle 156.3 cm or 61.54 inches Rear Axle 157 cm or 61.81 inches Ground clearance: 21.0 cm / 8.27 inches Ground clearance: 21.0 cm / 8.27 inches Max. Towing Capacity Weight 1400 Kg or 3086.47 lbs |
Final result for Example 1:
Cell | Title | Text |
A2 | Engine size - Displacement - Engine capacity: | 999 cm3 or 61 cu-in |
A3 | Body: SUV / TT Num. of Doors: | 5 |
A4 | Wheelbase: | 267.4 cm or 105.28 inches |
A5 | Length: | 434.1 cm or 170.91 inches |
A6 | Width: | 180.4 cm or 71.02 inches |
A7 | Height: | 169.3 cm or 66.65 inches |
A8 | Front Axle | 156.3 cm or 61.54 inches |
A9 | Rear Axle | 157 cm or 61.81 inches |
A10 | Ground clearance: | 21.0 cm / 8.27 inches |
A11 | Ground clearance: | 21.0 cm / 8.27 inches |
A12 | Max. Towing Capacity Weight | 1400 Kg or 3086.47 lbs |
Now the tricky part is that there is no marker distinguishing the titles from the text, some have ":" at the end, some not...
Also, although the titles appear always in the same order, if there is no information regarding one of these, it simply does not appear in the text.
Example 2 (Equal to example 1, but with no Front Axle information):
Engine size - Displacement - Engine capacity: 999 cm3 or 61 cu-in Body: SUV / TT Num. of Doors: 5 Wheelbase: 267.4 cm or 105.28 inches Length: 434.1 cm or 170.91 inches Width: 180.4 cm or 71.02 inches Height: 169.3 cm or 66.65 inches Rear Axle 157 cm or 61.81 inches Ground clearance: 21.0 cm / 8.27 inches Ground clearance: 21.0 cm / 8.27 inches Max. Towing Capacity Weight 1400 Kg or 3086.47 lbs |
As there are no markers for the titles, I am thinking that the best is to set the titles as constants.
This way if more titles are introduced into the system, I can simply add them to the code, and add a number to the Integer:
Code start example:
Dim Const Title1 = "Engine size - Displacement - Engine capacity:"
Dim Const Title2 = "Body: SUV / TT Num. of Doors:"
Dim Const Title3 = "Wheelbase:"
Dim x As Integer
For x = 1 To 3
Having these constants defined, it would be possible to do the following:
Step 1 -Search for the first title in the code; If not found, search for title2; If found, paste it in the cell below;
Step 2 -Search for the following title; if found, paste the text contained between the first found title and the second found title, one cell down, one cell to the left; If not found, search the next title;
Step3 - Loop
And repeating this process untill all titles present in the original cell are separated below:
A | B | |
1 | Engine size - Displacement - Engine capacity: 999 cm3 or 61 cu-in Body: SUV / TT Num. of Doors: 5 Wheelbase: 267.4 cm or 105.28 inches Length: 434.1 cm or 170.91 inches Width: 180.4 cm or 71.02 inches Height: 169.3 cm or 66.65 inches Front Axle 156.3 cm or 61.54 inches Rear Axle 157 cm or 61.81 inches Ground clearance: 21.0 cm / 8.27 inches Ground clearance: 21.0 cm / 8.27 inches Max. Towing Capacity Weight 1400 Kg or 3086.47 lbs | |
2 | Engine size - Displacement - Engine capacity: | 999 cm3 or 61 cu-in |
3 | Body: SUV / TT Num. of Doors: | 5 |
4 | Wheelbase: | 267.4 cm or 105.28 inches |
5 | Length: | 434.1 cm or 170.91 inches |
6 | Width: | 180.4 cm or 71.02 inches |
7 | Height: | 169.3 cm or 66.65 inches |
8 | Front Axle | 156.3 cm or 61.54 inches |
9 | Rear Axle | 157 cm or 61.81 inches |
10 | Ground clearance: | 21.0 cm / 8.27 inches |
11 | Ground clearance: | 21.0 cm / 8.27 inches |
12 | Max. Towing Capacity Weight | 1400 Kg or 3086.47 lbs |
My question is if this is possible, or if there is a better way of doing it, I am searching for ideas.
Can someone advise if I am thinking well here?