Retroshift
Board Regular
- Joined
- Sep 20, 2016
- Messages
- 119
- Office Version
- 2019
- Platform
- Windows
Hi,
I have a userform with text fields and checkboxes. The data entered in the userform will be transfered to a new row in the named table "tblColleagues". This table already contains a few rows with data but the named table range also covers lots of empty rows. How is it possible to make the userform data being entered in the first entirely empty row starting from the top below the header to the bottom of the named table? The code below only adds new rows after the bottom of the named range, ignoring all the empty rows within the table itself.
The data input of "fullparttime" should also be limited to a number =>0<=100 as this is a percentage.
Anyone has an idea on how to alter the code below accordingly?
I have a userform with text fields and checkboxes. The data entered in the userform will be transfered to a new row in the named table "tblColleagues". This table already contains a few rows with data but the named table range also covers lots of empty rows. How is it possible to make the userform data being entered in the first entirely empty row starting from the top below the header to the bottom of the named table? The code below only adds new rows after the bottom of the named range, ignoring all the empty rows within the table itself.
The data input of "fullparttime" should also be limited to a number =>0<=100 as this is a percentage.
Anyone has an idea on how to alter the code below accordingly?
VBA Code:
Sub cbAdd_Click()
Dim firstname As String
firstname = txtFirstName.Text
Dim lastname As String
lastname = txtLastName.Text
Dim shortname As String
shortname = txtShortName.Text
Dim fullparttime As String
fullparttime = txtFullparttime.Text 'incorrect data type? percentage
Dim wsh As Worksheet
Set wsh = ThisWorkbook.Worksheets("List")
Set tbl = wsh.ListObjects("tblColleagues")
Dim newRow As ListRow
Set newRow = tbl.ListRows.ADd 'positioning needs to loop within the named table "tblColleagues" until the first empty row, starting from the first row below the header
With newRow
.Range(1) = firstname
.Range(2) = lastname
.Range(3) = shortname
.Range(5) = fullparttime 'Condition: numeric =>0<=100 as this is a percentage
If cbx1.Value = True Then
.Range(4) = "x"
End If
If cbx2.Value = True Then
.Range(6) = "x"
End If
End With
End Sub