Dim x As Integer 'LOOPER SHEET ONE
Dim y As Integer 'LOOPER SHEET TWO
Dim i As Integer 'COLUMN LOCATION VARIABLE
Dim j As Integer 'LOOKUP LOCATOR VARIABLE
Dim dT As Date
dT = Now()
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "TEXT"
.ColumnCount = 6
.AddItem
.Column(0, i) = "TEXT"
.Column(1, i) = ""
.Column(2, i) = ""
.Column(3, i) = ""
.Column(4, i) = ""
.Column(5, i) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "SPACER ROW"
.AddItem
.Column(0, i + 1) = dT
.Column(1, i + 1) = ""
.Column(2, i + 1) = ""
.Column(3, i + 1) = ""
.Column(4, i + 1) = ""
.Column(5, i + 1) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "SPACER ROW"
.AddItem
.Column(0, i + 2) = ""
.Column(1, i + 2) = ""
.Column(2, i + 2) = ""
.Column(3, i + 2) = ""
.Column(4, i + 2) = ""
.Column(5, i + 2) = ""
End With
For x = 0 To ListBox1.ListCount - 1 'LOOP THROUGH CNS DATA SHEET
For y = 0 To ListBox2.ListCount - 1 'LOOP THROUGH DATABASE SHEET
If ListBox2.List(y, 0) = ListBox1.List(x, 5) Then 'LOOKUP CNS NAMES ON DATABASE
j = y 'SAVE LOCATION ADDRESS IN VARIABLE J
End If
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "TEXT"
.AddItem
.Column(0, i + 3) = "TEXT"
.Column(1, i + 3) = ""
.Column(2, i + 3) = ""
.Column(3, i + 3) = ""
.Column(4, i + 3) = ""
.Column(5, i + 3) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "PLANT NAME"
.AddItem
.Column(0, i + 4) = ListBox1.List(x, 5)
.Column(1, i + 4) = ""
.Column(2, i + 4) = ""
.Column(3, i + 4) = ""
.Column(4, i + 4) = ""
.Column(5, i + 4) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "LQA / HNW"
.AddItem
.Column(0, i + 5) = "LQA=" & Format(ListBox2.List(j, 19), "00000.00")
.Column(1, i + 5) = "HNW=" & Format(ListBox2.List(j, 21), "00000.00")
.Column(2, i + 5) = ""
.Column(3, i + 5) = ""
.Column(4, i + 5) = ""
.Column(5, i + 5) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "OCTAVE BANDS 1 - 6"
.AddItem
.Column(0, i + 6) = "LQ1=" & Format(ListBox2.List(j, 10), "00000.00")
.Column(1, i + 6) = "LQ2=" & Format(ListBox2.List(j, 11), "00000.00")
.Column(2, i + 6) = "LQ3=" & Format(ListBox2.List(j, 12), "00000.00")
.Column(3, i + 6) = "LQ4=" & Format(ListBox2.List(j, 13), "00000.00")
.Column(4, i + 6) = "LQ5=" & Format(ListBox2.List(j, 14), "00000.00")
.Column(5, i + 6) = "LQ6=" & Format(ListBox2.List(j, 15), "00000.00")
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "OCTAVE BANDS 7 - 9"
.AddItem
.Column(0, i + 7) = "LQ7=" & Format(ListBox2.List(j, 16), "00000.00")
.Column(1, i + 7) = "LQ8=" & Format(ListBox2.List(j, 17), "00000.00")
.Column(2, i + 7) = "LQ9=" & Format(ListBox2.List(j, 18), "00000.00")
.Column(3, i + 7) = ""
.Column(4, i + 7) = ""
.Column(5, i + 7) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "PNO"
.AddItem
.Column(0, i + 8) = "PNO=" & Format(ListBox2.List(j, 1), "00000.00")
.Column(1, i + 8) = ""
.Column(2, i + 8) = ""
.Column(3, i + 8) = ""
.Column(4, i + 8) = ""
.Column(5, i + 8) = ""
End With
With ListBox3 'PRINT FORMATTING REQUIREMENTS - "SPACER ROW"
.AddItem
.Column(0, i + 9) = ""
.Column(1, i + 9) = ""
.Column(2, i + 9) = ""
.Column(3, i + 9) = ""
.Column(4, i + 9) = ""
.Column(5, i + 9) = ""
End With
Next y
i = i + 7 'INCREMENT VAR i FOR NEXT LIST ITEM
Next x
End Sub
For some reason when it created the new listbox contents (and it does do that bit correctly) it also adds thousands of rows to the bottom of the new listbox. This is now causing some issues to the next stage of my work.
Bookmarks