Requirement:
I'm trying to create a data entry form (VBA userform) for a time-sheet.
The form has a limit of 12 inputs (rows) at a time, with the employee names and the type/number of hours worked.
To avoid typing the "date"12 times, I put a single field for the date, since it will be the same for each row. The problem is when there are less than 12 inputs. The code that I'm using brings the date 12 times anyway. Is there any other code that I can use to insert the date according to number of inputs/rows?
Solution:
For lngCount = 0 To 11 If Me.Controls("ComboStaff" & lngCount + 1).Text = vbNullString Then Exit Sub AddNew.Offset(lngCount, 0).Resize(, 8).Value = Array(txtDate.Text, _ ComboStore.Text, _ Me.Controls("txtTravel" & lngCount + 1).Text, _ Me.Controls("ComboStaff" & lngCount + 1).Text, _ Me.Controls("txtWork" & lngCount + 1).Text, _ Me.Controls("txtOT" & lngCount + 1).Text, _ Me.Controls("txtTrvOT" & lngCount + 1).Text, _ Me.Controls("txtSpecial" & lngCount + 1).Text) Next lngCount
Obtained from the OzGrid Help Forum.
Solution provided by pike.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to create data entry userforms |
How to use a UserForm: CheckBox Checked if Listbox column 5 text matched CheckBox text |
How to auto-generate unique ID in Excel VBA UserForm |
How to bring an excel userform message box above all other windows |
How to calculate userform textbox and cell value for label caption |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.