Hi,
I seem to have a problem with my arrays (?) on this. I have a sheet in excel which relates to a number of tests. The number of tests varies, and the length of(number of rows occupied by) each test can vary as well. I need to reformat this to split each test into its own worksheet. The code I'm using is below:
I'm not sure where the problem is in this case, but I'm seeing 0 as the value in the third loop (second For loop) for the array elements although when the array is set in the first place, hovering over it seems to suggest that the correct values are being set. This seems to happen until array element 10, where it sets a value of 599 (this is the correct row for the last test). There are 11 elements in the array - although NumTests reports 12, this is due to the last increment of the variable in the first loop - haven't amended that just yet.
Anyone able to help out?
Cheers,
Dave
"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software." <-- Me
For all your testing needs: Forum1393
I seem to have a problem with my arrays (?) on this. I have a sheet in excel which relates to a number of tests. The number of tests varies, and the length of(number of rows occupied by) each test can vary as well. I need to reformat this to split each test into its own worksheet. The code I'm using is below:
Code:
Public Sub GrabData()
Application.ScreenUpdating = False
Cells(5, "G").Select ' This is the first test - find out how many tests there are to cover
NumTests = 1
While ActiveCell.Row < 65536
ReDim TestStart(NumTests) 'This allows us to vary the number of tests we are looking at
TestStart(NumTests) = Int(ActiveCell.Row)' Set the value of the array to the starting cell of the next test
Selection.End(xlDown).Select
NumTests = NumTests + 1
Wend
' Create a new sheet for each test and copy the test contents to it
For LoopCount = 1 To NumTests
Worksheets.Add
ActiveSheet.Name = LoopCount & " added"
Next LoopCount
' Gather the data for each test and copy it to its worksheet
Sheets("Planning Report3").Select
LoopCount = 1
For LoopCount = 1 To NumTests
StartCell = "A" & TestStart(LoopCount) ' StartCell should be "A5" in first case
If (LoopCount = NumTests) Then
EndCell = "H65536" 'Use end of worksheet if on last array element
Else
EndCell = "H" & (TestStart(LoopCount + 1) - 1) ' Otherwise use the start of the next test minus 1 to get the range for the test
End If
Range(StartCell, EndCell).Copy ' Copy the test
Sheets(LoopCount & " added").Select ' swap to the relevant sheet
Cells(1, 1).Select 'Pick a start
ActiveSheet.Paste ' Paste the copied test
Next LoopCount
I'm not sure where the problem is in this case, but I'm seeing 0 as the value in the third loop (second For loop) for the array elements although when the array is set in the first place, hovering over it seems to suggest that the correct values are being set. This seems to happen until array element 10, where it sets a value of 599 (this is the correct row for the last test). There are 11 elements in the array - although NumTests reports 12, this is due to the last increment of the variable in the first loop - haven't amended that just yet.
Anyone able to help out?
Cheers,
Dave
"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software." <-- Me
For all your testing needs: Forum1393