Hi All,
Trying to add worksheet names to a listbox based on a set criteria. The one line of code that doesn't work is.
If Workbooks(filename).ws.Cells(7, 2) = "Surname" Then
Not sure what it should be. ws is dimmed as worksheet
Trying to add worksheet names to a listbox based on a set criteria. The one line of code that doesn't work is.
If Workbooks(filename).ws.Cells(7, 2) = "Surname" Then
Not sure what it should be. ws is dimmed as worksheet
Code:
'I want worksheets added to the listbox only if cell(7,2) is equal to "Surname"
With Me.ListBox1
Me.ListBox1.Clear
For Each ws In Workbooks(filename).Worksheets
If Workbooks(filename).ws.Cells(7, 2) = "Surname" Then ' this line doesn't work.
.AddItem ws.Name
Else
End If
Next
End With