I'm stuck on what I'm doing wrong here and hoping there is any easy solution. The code works fine without the .clear but I'm just adding to the list each time I select a new option button and I want to clear the old data first.
VBA Code:
Private Sub LoadData1()
Dim ws As Worksheet
Set ws = Worksheets("Detail")
ListBox1.Clear '<<===This causes a problem no matter where I place it.
'I even created a separate button just to clear and still creates an issue when running
'the below
For irow = 18 To 850
If Trim(ws.Range("AH" & irow).Value) = 1 Then
With ListBox1
.ColumnCount = 5
.ColumnWidths = "40;80;80;80;5"
.AddItem
.List(i, 0) = Trim(ws.Range("O" & irow).Value) '<<===I get the error here
.List(i, 1) = Trim(ws.Range("P" & irow).Value)
.List(i, 2) = Trim(ws.Range("Q" & irow).Value)
.List(i, 3) = Trim(ws.Range("S" & irow).Value)
.List(i, 4) = "*"
i = i + 1
End With
End If
Next irow
Dim Arg1 As Range
Dim Arg2 As Range
Set Arg1 = ws.Range("AQ18:AQ847")
Set Arg2 = ws.Range("AH18:AH847")
txtSalaryAmt.Value = Format(Application.WorksheetFunction.SumIfs(Arg1, Arg2, 1) * 12, "#,###")
OptionButton3.Value = True
End Sub