I am still learning how to use arrays well, but this appears to be working until it starts the br loop. the computer fan starts running high and when i click on excel it says not responding. what am i doing wrong?
Code:
Public Sub ReadToFromArray()
ActiveWorkbook.Worksheets("Data").Select
Dim a As Long
a = Application.WorksheetFunction.CountA(ActiveWorkbook.Worksheets("Data").Range(Cells(2, 1), Cells(1048576, 1)))
PRnum = Array(1, 5, 10, 11, 13, 18, 20, 21, 22, 23, 25, 28, 29, 33, 35)
PRtext = Array("1", "5", "10", "11", "13", "18", "20", "21", "22", "23", "25", "28", "29", "33", "35")
ActiveWorkbook.Worksheets("Arrays").Select
' Declare dynamic array for Pri to Br
Dim Network As Variant
Network = ActiveWorkbook.Worksheets("Arrays").Range(Cells(4, 2), Cells(36, 16)).Value
'delete the data we will not be using "B4:P36"
'ActiveWorkbook.Worksheets("Data").Columns("AG:AY").EntireColumn.Delete
'ActiveWorkbook.Worksheets("Data").Columns("O:AE").EntireColumn.Delete
'ActiveWorkbook.Worksheets("Data").Columns("K:L").EntireColumn.Delete
'ActiveWorkbook.Worksheets("Data").Columns("H:I").EntireColumn.Delete
'ActiveWorkbook.Worksheets("Data").Columns("C:F").EntireColumn.Delete
ActiveWorkbook.Worksheets("Data").Select
' Declare dynamic array for entire data set
Dim Dataset As Variant
Dataset = ActiveWorkbook.Worksheets("Data").Range(Cells(2, 1), Cells(a + 1, 7)).Value
For p = 0 To UBound(PRnum)
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Select
'clean and populate primary data
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Rows("5:1048576").EntireRow.Delete
Dim x As Long
x = 0
For li = 1 To a
If Dataset(li, 1) = PRnum(p) And Dataset(li, 3) = PRnum(p) And Dataset(li, 7) > 0 Then
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 2).Value = Dataset(li, 2)
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 3).Value = Dataset(li, 4)
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 4).Value = Round(Dataset(li, 7), 0)
If ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 4).Value <= ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 3).Value Then
Else
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 5).Value = ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 4).Value - ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(x + 5, 3).Value
End If
x = (x + 1)
Else
End If
Next li
Dim y As Long
y = Application.WorksheetFunction.CountA(ActiveWorkbook.Worksheets("BR" & PRnum(p)).Range(Cells(5, 2), Cells(1048576, 2)))
Dim Lines As Variant
Lines = ActiveWorkbook.Worksheets("BR" & PRnum(p)).Range(Cells(5, 2), Cells(y + 4, 2)).Value
For br = 1 To 33
For pli = 1 To y
For li2 = 1 To a
If Dataset(li2, 2) = Lines(pli, 1) And Dataset(li2, 1) = Network(p + 1, br) And Dataset(li2, 7) > 0 Then
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(pli + 4, (br * 2) + 12).Value = Dataset(li2, 4)
ActiveWorkbook.Worksheets("BR" & PRnum(p)).Cells(pli + 4, (br * 2) + 13).Value = Round(Dataset(li2, 7), 0)
GoTo FoundIt
Else
End If
Next li2
FoundIt:
Next pli
Next br
Next p
End Sub
Last edited: