Help with VBA Code to input Userform data to the next available column

stminz_

New Member
Joined
Aug 25, 2002
Messages
10
Hello...

I'm looking for help or input with a VBA code that allows me to add data/info from a user form to a worksheet (database) for each user. The user form has 4 users with a text field to allow me to add a value of their scan counts. There's also a text field that allows me to enter a time for each set of inputs. The way I need the data/info for each user and time to be added to the worksheet is in the next available empty column. In the example, row 1 includes the column headers and column A1:A6 includes the user names (user 1, user 2, user 3, user 4) and time. For the first input of data from the user form, the data would be added to column B for each user. The next set of data would be added to column C, etc. Below is what I have for the current code. Any help would be appreciated.

Thanks in advance!

Description of user form and worksheets
userform: frmForm​
worksheet: Database​

User form text fields
txtUser1ScannedPPH​
txtUser2ScannedPPH​
txtUser3ScannedPPH​
txtUser4ScannedPPH​
txtTimestamp​



Sub Submit()

Dim ws As Worksheet
Dim lastcol As Long

Set ws = ThisWorkbook.Sheets("Database")

'Finds the last blank column
lastcol = ws.Range("A" & Columns.Count).End(xlToLeft).Column + 1

With ws

ws.Range("B" & lastcol + 4).Value = frmForm.txtTimestamp.Value
ws.Range("B" & lastcol).Value = frmForm.txtUser1ScannedPPH.Value
ws.Range("B" & lastcol + 1).Value = frmForm.txtUser2ScannedPPH.Value
ws.Range("B" & lastcol + 2).Value = frmForm.txtUser3ScannedPPH.Value
ws.Range("B" & lastcol + 3).Value = frmForm.txtUser4ScannedPPH.Value
End With

End Sub

Users​
Scans​
Scans​
Scans​
Scans​
Scans​
Scans​
Scans​
Scans​
User 1​
User 2​
User 3​
User 4​
Time​
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,223
Messages
6,123,722
Members
449,116
Latest member
Aaagu

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