I have written a For each loop that I want to go through the range and test for the first condition and add the value to a combobox. ONLY If it cannot find that condition then I want it to execute the second for each loop and add all the values that match the condition.
I have written the below code and it says
Else without If
even though there is an IF
Dim Keys As Range, cell As Range
Set Keys = ThisWorkbook.Worksheets("keyHistory").Range("A2:A20000")
For Each cell In Keys
If cell.Value = WindowsUserName And cell.Offset(0, 4) = 1 Then Me.ComboBox1.AddItem cell.Value
Else
For Each cell In Keys
If cell.Offset(0, 4).Value = 1 And cell.Offset(0, 3) = "" Or cell.Value = "Spare" And cell.Offset(0, 4) = 1 Then Me.ComboBox1.AddItem cell.Value
Next cell
Next cell
Set Keys = Nothing