Hello everyone - I'm trying to get a nested for next loop to work. The inside loop one pulls some data based on dates, cost codes and puts it into a sheet. But I need to do this with up to 4 BusUnits at a time. The form that drives this and the inside loop work, its just when I tried to get an outside loop to go through 4 BusUnits, and particularly the attempt to use the variant in the If Then formula. I feel like I'm pretty close and any help is greatly appreciated.
Thanks
Dim arrbu() As Variant
Dim arrcc() As Variant
Dim bu As Variant
Dim BusUnit As Variant
Dim Ccode As Variant
arrbu = Array("Busunit1", "Busunit2", "Busunit3", "Busunit4")
arrcc = Array("ccode1", "ccode2", "ccode3", "ccode4")
For Each bu In arrbu
BusUnit = arrbu
Ccode = arrcc
For X = 5 To 10000 'wslr
If TExportws.Cells(X, 21) >= ws.Range("StartDate") And _
TExportws.Cells(X, 21) <= ws.Range("EndDate") And _
TExportws.Cells(X, 6) = Ccode And _
TExportws.Cells(X, 25) = BusUnit Then
ws.Cells(Row, 17) = Val(TExportws.Cells(X, 25)) 'Bus Unit Number
ws.Cells(Row, 18) = TExportws.Cells(X, 6) 'Cost Code
ws.Cells(Row, 19) = TExportws.Cells(X, 7) 'Description
ws.Cells(Row, 20) = TExportws.Cells(X, 8) 'Old Value
ws.Cells(Row, 21) = TExportws.Cells(X, 9) 'New Value
ws.Cells(Row, 22) = TExportws.Cells(X, 10) 'Previous Budget - Line Item
ws.Cells(Row, 23) = TExportws.Cells(X, 11) 'Revised Budget - Line Item
ws.Cells(Row, 24) = TExportws.Cells(X, 12) 'Increase / (Decrease) - Line Item Budget
ws.Cells(Row, 25) = TExportws.Cells(X, 14) 'Previous Budget - Cost Code
ws.Cells(Row, 26) = TExportws.Cells(X, 15) 'Revised Budget - Cost Code
ws.Cells(Row, 27) = TExportws.Cells(X, 16) 'Increase / (Decrease) - Cost Code Budget
ws.Cells(Row, 28) = TExportws.Cells(X, 13) 'Notes
ws.Cells(Row, 17).NumberFormat = "General"
ws.Cells(Row, 18).NumberFormat = "General"
ws.Cells(Row, 20).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 21).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 22).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 23).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 24).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 25).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
ws.Cells(Row, 26).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
ws.Cells(Row, 27).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
Row = Row + 1
End If
Next X
Next bu
Thanks
Dim arrbu() As Variant
Dim arrcc() As Variant
Dim bu As Variant
Dim BusUnit As Variant
Dim Ccode As Variant
arrbu = Array("Busunit1", "Busunit2", "Busunit3", "Busunit4")
arrcc = Array("ccode1", "ccode2", "ccode3", "ccode4")
For Each bu In arrbu
BusUnit = arrbu
Ccode = arrcc
For X = 5 To 10000 'wslr
If TExportws.Cells(X, 21) >= ws.Range("StartDate") And _
TExportws.Cells(X, 21) <= ws.Range("EndDate") And _
TExportws.Cells(X, 6) = Ccode And _
TExportws.Cells(X, 25) = BusUnit Then
ws.Cells(Row, 17) = Val(TExportws.Cells(X, 25)) 'Bus Unit Number
ws.Cells(Row, 18) = TExportws.Cells(X, 6) 'Cost Code
ws.Cells(Row, 19) = TExportws.Cells(X, 7) 'Description
ws.Cells(Row, 20) = TExportws.Cells(X, 8) 'Old Value
ws.Cells(Row, 21) = TExportws.Cells(X, 9) 'New Value
ws.Cells(Row, 22) = TExportws.Cells(X, 10) 'Previous Budget - Line Item
ws.Cells(Row, 23) = TExportws.Cells(X, 11) 'Revised Budget - Line Item
ws.Cells(Row, 24) = TExportws.Cells(X, 12) 'Increase / (Decrease) - Line Item Budget
ws.Cells(Row, 25) = TExportws.Cells(X, 14) 'Previous Budget - Cost Code
ws.Cells(Row, 26) = TExportws.Cells(X, 15) 'Revised Budget - Cost Code
ws.Cells(Row, 27) = TExportws.Cells(X, 16) 'Increase / (Decrease) - Cost Code Budget
ws.Cells(Row, 28) = TExportws.Cells(X, 13) 'Notes
ws.Cells(Row, 17).NumberFormat = "General"
ws.Cells(Row, 18).NumberFormat = "General"
ws.Cells(Row, 20).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 21).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 22).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 23).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 24).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
ws.Cells(Row, 25).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
ws.Cells(Row, 26).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
ws.Cells(Row, 27).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
Row = Row + 1
End If
Next X
Next bu