Sub thoughts()
curMS = inputYear + " MasterSheet"
curOOT = inputYear + " OOT DATA"
curMI = inputYear + " MI DATA"
Dim yval As Integer
Dim xval As Integer
Dim classval As Integer
Dim a As Integer
Dim sh As Worksheet, lrow As Long, j As Long, result
Dim arr27, arr9, arr7, i As Long, mystr As String
Dim crit1 As String, crit2 As String
Dim q As Long, w As Long, e As Long
'If IsError(Evaluate(curOOT & "!A1")) Then
'this handles errors if the sheet isnt found
' MsgBox "Sheet " & Chr(34) & "OOT DATA" & Chr(34) & " is not found", vbCritical, "Error"
' Exit Sub
'Else
Set sh = Sheets(curOOT)
'End If
lrow = sh.Cells(Rows.Count, "a").End(xlUp).Row
'calc the last row in the OOt sheet listed above
If lrow = 1 Then
'error handling for lacking rows
If sh.Cells(1, 9) = "CO" And sh.Cells(1, 27) = "class 12" Then
Sheets.Add.Range("a1").Value = sh.Cells(1, 7).Value
Exit Sub
End If
End If
ReDim result(1 To lrow, 1 To 1)
For q = 0 To Sheet1.ListBox2.ListCount - 1
arr7 = sh.Range("g1:g" & lrow) 'Factory Arr 7 for the 7th row, sets the range from g1 to g-last row
arr9 = sh.Range("i1:i" & lrow) 'country
arr27 = sh.Range("aa1:aa" & lrow) 'class
crit1 = "CO"
crit2 = "Class 11"
xval = ((q * 3) + 4) 'offset
'pull country from (xval,1) = country code
'ReDim result(1 To lrow, 1 To 1)
For w = 1 To 5
If w = 1 Then
yval = 18
crit2 = "Class 12"
For i = 1 To lrow
If arr9(i, 1) = crit1 And arr27(i, 1) = crit2 Then
If InStr(mystr, " " & arr7(i, 1) & " ") = 0 Then
mystr = mystr & " " & arr7(i, 1) & " "
j = j + 1
result(j, 1) = arr7(i, 1)
End If
End If
Next
If j > 0 Then
'Application.ScreenUpdating = 0
With Sheets(curMS)
.Range(.Cells(yval, xval), .Cells(yval + 2, xval)) = result
End With
'Application.ScreenUpdating = 1
End If
End If
If w = 2 Then
yval = 22
crit2 = "Class 11"
For i = 1 To lrow
If arr9(i, 1) = crit1 And arr27(i, 1) = crit2 Then
If InStr(mystr, " " & arr7(i, 1) & " ") = 0 Then
mystr = mystr & " " & arr7(i, 1) & " "
j2 = j2 + 1
result(j2, 1) = arr7(i, 1)
End If
End If
Next
If j > 0 Then
'Application.ScreenUpdating = 0
With Sheets(curMS)
.Range(.Cells(yval, xval), .Cells(yval + 2, xval)) = result
End With
'Application.ScreenUpdating = 1
End If
End If
If w = 3 Then
yval = 26
classval = 13
End If
If w = 4 Then
yval = 30
classval = 9
End If
If w = 5 Then
yval = 36
classval = 14
End If
'ReDim result(1 To lrow, 1 To 1)
Next
Next
End Sub
Bookmarks