How can I delete row from userform?

  • Thread starter Thread starter Alen32
  • Start date Start date
A

Alen32

I have userform with one combox which contains products name from sheet 1
and cells a2:a50. I want to choose one produkt name in combobox and delete
row where this product name is?
 
How did the product names get in the combobox. did you use the rowsource
property? Are you droping the userform as soon as the selection is made, or
can the user then select more to delete?
 
I gave name to cell interval A2:a50 and entered that name in combobox
property "row source". There is nothing more to choose. I want just to
select one product name in combobox and delete row where product name is.
 
Try this:


Option Explicit
Public Cleared As Boolean

Private Sub ComboBox1_Change()
Dim i As Integer
If Not Cleared Then
With Sheets(1)
i = Application.Match(Me.ComboBox1.Value, Range("MyList"), 0)
Cleared = True
.Range("MyList")(i).EntireRow.Delete Shift:=xlUp

End With
End If
Cleared = False
Me.Hide
End Sub

************************
Notice that the variable Cleared is declared Public and placed at the TOP of
the module, not inside the macro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top