Listbox Question

G

Greg B

I have userform4 where I have put a command button and listbox on it, this
is connected to a sheet called Hidden.

I want to allow the user to select the text in the userbox and click on the
command button to delete that certain entry on the worksheet.

Is this possible, How to I acheive this to happen.

Thanks in advance

Greg
 
D

Dave Peterson

This worked ok for me:

Option Explicit
Private Sub CommandButton1_Click()
If Me.ListBox1.ListIndex > -1 Then
With Worksheets("Hidden")
.Rows(Me.ListBox1.ListIndex + 1).Delete
Call UserForm_Initialize
End With
End If
End Sub
Private Sub UserForm_Initialize()
Dim myArray As Variant

With Worksheets("Hidden")
myArray = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)).Value
If IsArray(myArray) Then
'ok
Else
myArray = Array(myArray)
End If
End With
Me.ListBox1.List = myArray
End Sub

My list was in A1:Axx on a worksheet called Hidden.
 

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

Similar Threads


Top