Hello,
I am using the code below to pass some information from a worksheet to a listbox, and it works fine. Well, rather it worked fine when I was just looking for the first value in Column A. But when I added the second parameter ("And sh2.Range("E" & i).Value = "" ") the code no longer returns a value. I just want to return the row information if the value in Column E of the same row is blank.
Did I get the syntax wrong? I appreciate any input.
I am using the code below to pass some information from a worksheet to a listbox, and it works fine. Well, rather it worked fine when I was just looking for the first value in Column A. But when I added the second parameter ("And sh2.Range("E" & i).Value = "" ") the code no longer returns a value. I just want to return the row information if the value in Column E of the same row is blank.
Did I get the syntax wrong? I appreciate any input.
VBA Code:
Private Sub RepairsDueButton_Click()
Dim sh As Object, sh2 As Worksheet
Dim i As Long
Set sh = Sheets("Plant Status")
Set sh2 = Sheets("Repair Log")
sh.RepairHistory.Clear
For i = 1 To sh2.Range("A" & Rows.Count).End(3).Row
If sh2.Range("A" & i).Value = sh.RepairedDevice.Value And sh2.Range("E" & i).Value = "" Then
With sh.RepairHistory
.AddItem
.List(.ListCount - 1, 0) = sh2.Cells(i, 2).Value
.List(.ListCount - 1, 1) = sh2.Cells(i, 3).Value
.List(.ListCount - 1, 2) = sh2.Cells(i, 4).Value
.List(.ListCount - 1, 3) = sh2.Cells(i, 5).Value
.List(.ListCount - 1, 4) = sh2.Cells(i, 6).Value
End With
End If
Next
End Sub