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
User form text fields
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 Sub
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 WithEnd Sub
Users | Scans | Scans | Scans | Scans | Scans | Scans | Scans | Scans |
User 1 | ||||||||
User 2 | ||||||||
User 3 | ||||||||
User 4 | ||||||||
Time |