ListBox AddItem/RemoveItem

RBrown

Board Regular
Joined
Mar 7, 2004
Messages
52
I have a list of order numbers in column “A” of sheet2 used to populate a userform listbox.
Is it possible to edit the list box and the sheet from the userform (add or delete) even though sheet2 is not the active sheet when the userform is loaded?
Any help will be appreciated.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Yep you sure can do that.....

Private Sub UserForm_initialize()
dim l as long
dim r as range

set r = sheets("Sheet2").Range("A1")

l = 1 'Comment this line if the Column A does not have header rows
Listbox1.Clear
while r.Offset(l,0).Value <> ""
ListBox1.AddItem r.Offset(l,0).Value
l=l+1
Wend

End Sub
 
Upvote 0
Thanks viquarshaikh,
This works as far as populating the listbox from an inactive sheet but is there a way to edit the listbox and the worksheet (add or delete cell values) from the userform.
 
Upvote 0
Have a command Button on the Form and on its Click Event you could simply remove a selected item from a listbox by using the .Remove method..... Using the same value delete it from the Inactive sheet too by finding and deleting it....(though take care to delete the entire row)

However, to add a value what you could do is, just have a textbox on the form type some values into it and on the click event of another button add the typed text into the Listbox and the Excel Column
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top