I have the following code courtesy of Rick Rothstein. I've edited it a bit, to change columns used from D & F to B & N
and added comments (trying to follw the code he wrote, the comments may be wrong and if anyone could fix it would be appreciated)
My problem is that there are some dates in columns P,Q,R,S,T
After running the code, the dates don't match what they should be.
(other columns, other data, which *seems* to copy ok at the moment)
Please ignore all dots, they are spacers for this post.
There are more than 1 row. Some may contain only 1 field in B and 1 field in N.
B and N will have the same number of comma delimited fields.
eg: Before =
Column B...........................Column N.........................................................Column P........Column Q........Column R........Column S........Column T
AU1234, AU1235, AU1236.....M98765 (40AB), M87654 (40AC), M76543 (30AD)....2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
After: SHOULD BE:
Column B...........................Column N.........................................................Column P........Column Q........Column R........Column S........Column T
AU1234.............................M98765 (40AB).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
AU1235.............................M87654 (40AC).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
AU1236.............................M76543 (30AD).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
But, What I'm actually getting is:
Column B...........................Column N.........................................................Column P........Column Q........Column R........Column S........Column T
AU1234.............................M98765 (40AB).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/03/30
AU1235.............................M87654 (40AC).................................................2013/03/19.....2013/03/17.....2012/02/15.....2013/04/23.....2013/04/23
AU1236.............................M76543 (30AD).................................................2013/05/22.....2013/03/17.....2013/04/07.....2013/04/23.....2013/04/23
as you can see, some of the dates are correct, but there appear to be some random dates also.
Also, at the end of the code, after everything has been split to multiple rows, I would like to put a space between the letters and numbers in Column B
eg: AU 1234
AU 1235
but that's not too important, I can do without that if the Comma split is working correctly.
I can email sample .csv's if required for testing and code changing purposes.
Tia
Al
and added comments (trying to follw the code he wrote, the comments may be wrong and if anyone could fix it would be appreciated)
My problem is that there are some dates in columns P,Q,R,S,T
After running the code, the dates don't match what they should be.
(other columns, other data, which *seems* to copy ok at the moment)
Please ignore all dots, they are spacers for this post.
There are more than 1 row. Some may contain only 1 field in B and 1 field in N.
B and N will have the same number of comma delimited fields.
eg: Before =
Column B...........................Column N.........................................................Column P........Column Q........Column R........Column S........Column T
AU1234, AU1235, AU1236.....M98765 (40AB), M87654 (40AC), M76543 (30AD)....2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
After: SHOULD BE:
Column B...........................Column N.........................................................Column P........Column Q........Column R........Column S........Column T
AU1234.............................M98765 (40AB).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
AU1235.............................M87654 (40AC).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
AU1236.............................M76543 (30AD).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/04/23
But, What I'm actually getting is:
Column B...........................Column N.........................................................Column P........Column Q........Column R........Column S........Column T
AU1234.............................M98765 (40AB).................................................2013/03/19.....2013/03/17.....2013/04/27.....2013/04/23.....2013/03/30
AU1235.............................M87654 (40AC).................................................2013/03/19.....2013/03/17.....2012/02/15.....2013/04/23.....2013/04/23
AU1236.............................M76543 (30AD).................................................2013/05/22.....2013/03/17.....2013/04/07.....2013/04/23.....2013/04/23
as you can see, some of the dates are correct, but there appear to be some random dates also.
Also, at the end of the code, after everything has been split to multiple rows, I would like to put a space between the letters and numbers in Column B
eg: AU 1234
AU 1235
but that's not too important, I can do without that if the Comma split is working correctly.
I can email sample .csv's if required for testing and code changing purposes.
Tia
Al
Code:
Dim R As Long, C As Long, X As Long, LastRow As Long, LastColumn As Long, RowCount As Long
Dim Index As Long, Data As Variant, RowsOut As Variant, ItemsB() As String, ItemsN() As String
'Find last row from Column B eg:100
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
'Find last column from Row 2 eg: Y
LastColumn = Cells(2, Columns.Count).End(xlToLeft).Column
'Set data to be range A2 to Y100
Data = Range("A2").Resize(LastRow - 1, LastColumn)
'Start on Row 2
Index = 2
'Start with 1 and go to end of data (not sure what UBound is? does it mean entire array? every cell?)
For R = 1 To UBound(Data)
'?????? somehow split based on "comma space" or "comma" (Data(R, 2) = Row, Column ? not sure why doing Row, Column when always used to thinking in Column, Row
ItemsB = Split(Replace(Data(R, 2), ", ", ","), ",")
ItemsN = Split(Replace(Data(R, 14), ", ", ","), ",")
'I'm lost here
RowCount = UBound(ItemsB) + 1
ReDim RowsOut(1 To RowCount, 1 To LastColumn)
For X = 1 To RowCount
For C = 1 To LastColumn
RowsOut(X, C) = Data(R, C)
Next
RowsOut(X, 2) = ItemsB(X - 1)
RowsOut(X, 14) = ItemsN(X - 1)
Next
Cells(Index, "A").Resize(RowCount, LastColumn) = RowsOut
Index = Index + RowCount
'I find myself again, go back up to next R
Next