Hi all,
I am a newbie in VBA and I need help with the dilemma I have.
I have a listbox and a delete button in a frame with named range, lstRates,=OFFSET(ConKiloRates!$A$2,0,0,COUNTA(ConKiloRates!$A:$A) -1,11).
My problem is when I delete the last item in the listbox. It displays Runtime error 380 and my lstRange range then resets to =OFFSET(ConKiloRates!#REF!,0,0,COUNTA(ConKiloRates!$A:$A) -1,11) in the Name Manager.
ConKiloRates is the worksheet where I save the items added from the listbox. Once the user deletes an item in the listbox, I also want to delete that record from the worksheet ConKiloRates.
Appreciate your help. Thanks.
I am a newbie in VBA and I need help with the dilemma I have.
I have a listbox and a delete button in a frame with named range, lstRates,=OFFSET(ConKiloRates!$A$2,0,0,COUNTA(ConKiloRates!$A:$A) -1,11).
My problem is when I delete the last item in the listbox. It displays Runtime error 380 and my lstRange range then resets to =OFFSET(ConKiloRates!#REF!,0,0,COUNTA(ConKiloRates!$A:$A) -1,11) in the Name Manager.
ConKiloRates is the worksheet where I save the items added from the listbox. Once the user deletes an item in the listbox, I also want to delete that record from the worksheet ConKiloRates.
Code:
'Delete button
Private Sub CommandButton2_Click()
Dim strRange As String
With ListBox1
strRange = .RowSource
Range(strRange).Cells(.ListIndex + 1, 1).EntireRow.Delete
.RowSource = vbNullString
.RowSource = strRange
End With
End Sub
Appreciate your help. Thanks.