star79
04-07-2011, 04:12 AM
Hi All,
Well my hope is that this would be an easy one but my brain cells are depleting rapidly after battling with this all morning, most of the tasks are done apart from one. - explained below
I have attached 2 files (Before.xlsm & After.xlsm)
Before - contains all the data in one column - in chunks of a multiple values in between a "Start time and date" to "[END]"
After - this shows the columns are split correctly taking the right data in each however there is one problem:
The headers of each column should not be the same as that in "A1". Ive been battling all morning to try and get the true values from the list in the before file to append to when the split actually happens, but to no avail.
im guessing that line 17 : Range("B1", Cells(1, Columns.Count).End(xlToLeft)).Value = [A1] is the culprit.:confused:
I thank you in advance,
here the code im using:
Option Explicit
Sub SplitToColumns()
Dim FR As Long
Dim Rw As Long
Dim Arr As Variant
Application.ScreenUpdating = False
Arr = Columns(1).SpecialCells(xlConstants)
For Rw = LBound(Arr) To UBound(Arr)
If Left(Arr(Rw, 1), 5) = "Start" Then
FR = Rw
ElseIf Left(Arr(Rw, 1), 5) = "[END]" Then
Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Resize(Rw - FR + 1).Value _
= Range(Cells(FR, "A"), Cells(Rw, "A")).Value
End If
Next Rw
Columns(1).Delete
Range("B1", Cells(1, Columns.Count).End(xlToLeft)).Value = [A1]
Columns(1).Delete
Columns.AutoFit
Application.ScreenUpdating = True
End Sub
Well my hope is that this would be an easy one but my brain cells are depleting rapidly after battling with this all morning, most of the tasks are done apart from one. - explained below
I have attached 2 files (Before.xlsm & After.xlsm)
Before - contains all the data in one column - in chunks of a multiple values in between a "Start time and date" to "[END]"
After - this shows the columns are split correctly taking the right data in each however there is one problem:
The headers of each column should not be the same as that in "A1". Ive been battling all morning to try and get the true values from the list in the before file to append to when the split actually happens, but to no avail.
im guessing that line 17 : Range("B1", Cells(1, Columns.Count).End(xlToLeft)).Value = [A1] is the culprit.:confused:
I thank you in advance,
here the code im using:
Option Explicit
Sub SplitToColumns()
Dim FR As Long
Dim Rw As Long
Dim Arr As Variant
Application.ScreenUpdating = False
Arr = Columns(1).SpecialCells(xlConstants)
For Rw = LBound(Arr) To UBound(Arr)
If Left(Arr(Rw, 1), 5) = "Start" Then
FR = Rw
ElseIf Left(Arr(Rw, 1), 5) = "[END]" Then
Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Resize(Rw - FR + 1).Value _
= Range(Cells(FR, "A"), Cells(Rw, "A")).Value
End If
Next Rw
Columns(1).Delete
Range("B1", Cells(1, Columns.Count).End(xlToLeft)).Value = [A1]
Columns(1).Delete
Columns.AutoFit
Application.ScreenUpdating = True
End Sub