GIVEN: Using VBScript, I am trying to rearrange the way data is presented in an excel document. I know that the data will always be in the following format:
A | B | C | D
--------------|------------------------------|-----|-----
1 ANGLE | 6 x 3-1/2 x 5-16 x 240 | 1 | C1054
2 SQAURE TUBE | 1-1/2 x 1-1/2 x 1/8 x 31-3/4 | 3 | C1588
3 DOM TUBE | 5-1/2 OD x 1" WALL | 4 | C1670
GOAL: My goal is to get it into this format:
A | B | C | D
----------------------------------|---------|-----|-------
1 6 X 3-1/2 X 5-16 ANGLE | 240 | 1 | C1054
2 1-1/2 X 1-1/2 X 1/8 SQAURE TUBE | 31-3/4 | 3 | C1588
3 5-1/2 OD X 1" WALL DOM TUBE | | 4 | C1670
My idea is to first insert blank columns between columns B and C. Then, I will use the split command to break up column B with little "x" where this intermediate step will look like:
A | B | C | D | E | F | G
--------------|----------|---------|------|--------|---|-------
1 ANGLE | 6 | 3-1/2 | 5-16 | 240 | 1 | C1054
2 SQAURE TUBE | 1-1/2 | 1-1/2 | 1/8 | 31-3/4 | 3 | C1588
3 DOM TUBE | 5-1/2 OD | 1" WALL | | | 4 | C1670
Next I will take and move column A to be between columns D and E. Then I will somehow mash the numbers together using " X " and then mash that column with the next to reach the goal.
My code in vbscript is:
'inserting 3 blank columns into given format
objSheet2.Columns("C:C").Insert xlToRight
objSheet2.Columns("C:C").Insert xlToRight
objSheet2.Columns("C:C").Insert xlToRight
'splitting
Split objSheet2.Columns("B:B"),"x"
'objSheet2.Columns("B:B").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
' TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
' Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
' :="x", FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2)), _
' TrailingMinusNumbers:=True
'moving column A between column E and F
objSheet2.Columns("A:A").Cut
objSheet2.Columns("F:F").Insert
I first recorded a macro and just pasted it into my vbscript all willy nilly and that obviously didn't work, that's why I have it commented out. The split command isn't working either. I'm getting a Type Mismatch error at the start of the Split line during the run. Note, in row 3 there is one less piece of information than the other lines have.
QUESTION: How do I arrive at my goal format from my given format using VBScript and possibly a split command?