saving data from user form to excel worksheet

VBAmalta89

Board Regular
Joined
Mar 25, 2011
Messages
116
Hi

I am new to this VBA business and I have created a user form using VBA in excel to capture data from users. Now i need to save the data from the text boxes and combo boxes I created to be stored in particular cells on particular worksheets. How can i do this?

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
This should get you started;
Code:
Private Sub CommandButton1_Click()
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'find first row in database
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = TextBox1.Value
.Range("B" & irow) = TextBox2.Value
.Range("C" & irow) = TextBox3.Value
End With
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""

End Sub


HTH
Colin
 
Upvote 0
Ok so I am managing to reference the columns but how do i reference the cells as well. For example how would i change the code you gave me if i want to store in cell D5?

THanks once again for your help.
 
Upvote 0
To send to a specific cell try;
Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
ws.Range("D5") = TextBox1.Value
ws.Range("D6") = TextBox2.Value
ws.Range("D7") = TextBox3.Value
End Sub


HTH
Colin
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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