HELP ListBox Save Data to Hidden Sheet, and ReLoad It upon opening

N

Nafhen

My experience with VB in Excel is limited so if some can help me
finish my final project that will be great.

I have a userform with a listbox, that I can add and delete records
from the listbox during each session while the form is open once I
close the form I loose my listbox values. I would like to load this
data upon closing the form ie when the form closes that data in the
list box will be sent to a page to be reloaded when the form is
reopened. Can some one show me the code for this. Thank you Nate

My form name is = frmServall
My Sheet name is = Sheet3 (where I want to save to and load from)
My listbox name is = Listbox1

if you need to see the file email me at (e-mail address removed) and I will
send it to you. Thanks Again.
 
D

drhalter

you need to start out with your initial data set in Sheet3, listed from A1
down.

in the userform initialize sub:
dim myrange as range

with sheets("Sheet3")
Set myrange = .Range(.Range("A1"), .Range("A1").End(xlDown))
end with

For Each c In myrange
Listbox1.AddItem c
Next c

then, before your form closes or unloads:

Sheets("Sheet3").Range(Sheets("Sheet3").Range("A1"),
_Sheets("Sheet3").Range("A1").End(xlDown)).Delete

For x = 1 To Listbox1.ListCount
Sheets("Sheet3").Cells(x,1) = Listbox1.List(x - 1, 0)
Next x
 
T

Tom Ogilvy

to write the list - in the terminate event:
for i = 0 to listbox1.Listcount - 1
worksheets("Sheet3").cells(i+1,1) = listbox1.list(i)
Next

to load the list - in the initialize event:


Dim rng as Range
with worksheets("Sheet3")
set rng = .range(.cells(1,1),.cells(1,1).end(xldown))
End with
Listbox1.List = rng.value
 

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

Top