Vba add data to cell from userform

A

adrian

Hi all,

I am new to Exell but have been tinkering with VBA in Word.
I would be very grateful if someone could set me off in
the right direction with this little task.

I have a userform that has 4 listboxes in.

Any suggestions on how best to code exell so the the
result from each of the listboxes are entered into
worksheet cells on the next available row.

ie
Listbox1 result = "Dog"
Listbox2 result = "Cat"

Find first row with no data added. Add "Dog" to cell ?1.
Add "Cat" to cell ?2 etc etc.

Any help with code would be much appreciated.

Adrian
 
B

Bob Phillips

With Range("A" & Cells(Rows.Count,"A").End(xlUp).Row+1)
.Offset(0,0).Value = Listbox1.Value
.Offset(0,1).Value = Listbox2.Value
.Offset(0,2).Value = Listbox3.Value
.Offset(0,3).Value = Listbox4.Value
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
A

adrian

Thanks bob, just the job

adrian
-----Original Message-----

With Range("A" & Cells(Rows.Count,"A").End (xlUp).Row+1)
.Offset(0,0).Value = Listbox1.Value
.Offset(0,1).Value = Listbox2.Value
.Offset(0,2).Value = Listbox3.Value
.Offset(0,3).Value = Listbox4.Value
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)




.
 
A

adrian

Bob,

I am getting a runtime error 1004
Application-defined or object-defined error

Come up when this code is run.

I have your code set as a commandbutton click event.
Eveything else seems to be OK
Any ideas what it could be?

Thanks for any further help you can offer

Adrian
 
B

Bob Phillips

Adrian,

It works in my tests. Are you sure your listboxes haven't been renamed from
the default?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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