Hi
I am having a problem i have never seen before and cannot work out why. I've searched for an answer but i've had no luck.
I have a table of data 57 columns wide. Columns 1 to 8 contain information such as name and date etc. Columns 9 to 57 show "production" numbers; each column represents a 30 minute period during the day. I'm trying to convert this table into a Tableau friendly format: i.e. Name, Date, Time and Production on all one row (one row per time per day per name)
I wrote the code below do this but when the For Loop gets to i=58, i seems to reset itself. If I have i in the watch window and a break point at "Next i", i get to 58 and when i resume the value of i in the watch window goes from 58 to " < Out of context> <out of="" context="">"<out of="" context="">. The code does not resume until i hit F5 again at which point i returns to 1.
Im pretty new to VBA so i'm hoping its an obvious newb mistake. Any help is appreciated!
</out></out>
I am having a problem i have never seen before and cannot work out why. I've searched for an answer but i've had no luck.
I have a table of data 57 columns wide. Columns 1 to 8 contain information such as name and date etc. Columns 9 to 57 show "production" numbers; each column represents a 30 minute period during the day. I'm trying to convert this table into a Tableau friendly format: i.e. Name, Date, Time and Production on all one row (one row per time per day per name)
I wrote the code below do this but when the For Loop gets to i=58, i seems to reset itself. If I have i in the watch window and a break point at "Next i", i get to 58 and when i resume the value of i in the watch window goes from 58 to " < Out of context> <out of="" context="">"<out of="" context="">. The code does not resume until i hit F5 again at which point i returns to 1.
Im pretty new to VBA so i'm hoping its an obvious newb mistake. Any help is appreciated!
Code:
Sub SmartestTableau()
Dim SourceArray As Variant
Dim OutputArray As Variant
SourceArray = Sheets("merged").UsedRange.Value
ReDim OutputArray(6, 1)
OutputArray(1, 1) = "Name"
OutputArray(2, 1) = ""
OutputArray(3, 1) = "Date"
OutputArray(4, 1) = "Time"
OutputArray(5, 1) = "Production"
OutputArray(6, 1) = "Time"
For i = 1 To UBound(SourceArray, 2)
If SourceArray(i, 1) = "Yes" Then
For j = 9 To 57
ReDim Preserve OutputArray(6, UBound(OutputArray, 2) + 1)
OutputArray(1, UBound(OutputArray, 2)) = SourceArray(i, 2)
OutputArray(2, UBound(OutputArray, 2)) = ""
OutputArray(3, UBound(OutputArray, 2)) = SourceArray(i, 8)
OutputArray(4, UBound(OutputArray, 2)) = SourceArray(8, j)
OutputArray(5, UBound(OutputArray, 2)) = SourceArray(i, j)
OutputArray(6, UBound(OutputArray, 2)) = SourceArray(8, j)
Next j
End If
Next i