VBA to capture data from User Form

Mattyads2011

New Member
Joined
Jun 16, 2011
Messages
23
I have creatoed a userform which I am intending for users to input data and I need this data to the be captured onto a Excel Spreadsheet in vasrious coloumns, populating new rows with each new entry.

Haven't got the first idea where to start, can anyone please help me?


I am using Excel 2003.

Thank you.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How do you want this to happen?

For the user to click a button once they've finished entering data?

Perhaps something like this?
Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim Next As Range
 
      Set ws = Worksheets("Data") ' change for the worksheet you want data to go to
 
      ' the following will find the next empty row
      ' it uses column A, change that if needed
 
      Set rngNext ws.Range("A" & Rows.Count).End(xlup).Offset(1)
 
      ' now put the data from the textboxes in columns A-D
 
       rngNext.Value = TextBox1.Value ' column A
 
       rngNext.Offset(,1).Value = TextBox2.Value ' column B
 
       rngNext.Offset(,2).Value = TextBox3.Value ' column C
 
       rngNext.Offset(,3).Value = TextBox4.Value ' column D
 
       ' unload and reshow form for further input - change UserForm1 if
       ' your form name is different
 
       Unload Me 
 
       UserForm1.Show
 
End Sub
That's a very simple example which should give you a start.

Post back if you need more help.:)
 
Upvote 0
How do you want this to happen?

For the user to click a button once they've finished entering data?

Perhaps something like this?
Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim Next As Range
 
      Set ws = Worksheets("Data") ' change for the worksheet you want data to go to
 
      ' the following will find the next empty row
      ' it uses column A, change that if needed
 
      Set rngNext ws.Range("A" & Rows.Count).End(xlup).Offset(1)
 
      ' now put the data from the textboxes in columns A-D
 
       rngNext.Value = TextBox1.Value ' column A
 
       rngNext.Offset(,1).Value = TextBox2.Value ' column B
 
       rngNext.Offset(,2).Value = TextBox3.Value ' column C
 
       rngNext.Offset(,3).Value = TextBox4.Value ' column D
 
       ' unload and reshow form for further input - change UserForm1 if
       ' your form name is different
 
       Unload Me 
 
       UserForm1.Show
 
End Sub
That's a very simple example which should give you a start.

Post back if you need more help.:)


I think 'Dim Next As Range' should be 'Dim rngNext As Range'.
 
Upvote 0
It doesn't actually matter - there's no Option Explicit.

What does matter is the missing = in the line that sets the range reference.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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