I have created a VBA Userform to send data to the main database worksheet (Database) as well as a table on a new worksheet (New Entries) that is used to temporarily store information until after the Userform is closed. The data from the Userform correctly adds to the database worksheet (Database) in the correct position, but on the second worksheet (New Entries) the Userform mimics the row position of sheet1 (Database) instead of starting at the top row of the table. How can I get the Userform (once opened) to start at the top row of the sheet2 (New Entries) table? I may have up to 19 data rows in this table range (A3:M21).
Below is the code that works perfectly well, except for the positioning of the "New Entries" worksheet table:
Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] 'Identifying the last row
With frmForm
.txtLegalName.Value = ""
.txtTransitionDate.Value = ""
.txtAccountID.Value = ""
.optCAM.Value = False
.optAM.Value = False
.txtCurrentManager.Value = ""
.txtTransitioningTo.Value = ""
.cmbDivision.Clear
.cmbDivision.AddItem "Brevard"
.cmbDivision.AddItem "Gainesville"
.cmbDivision.AddItem "Jacksonville"
.cmbDivision.AddItem "Ocala"
.cmbDivision.AddItem "Orlando"
.cmbDivision.AddItem "Sarasota"
.cmbDivision.AddItem "Tampa"
.cmbDivision.AddItem "Volusia"
.cmbAssociationType.Clear
.cmbAssociationType.AddItem "SFH"
.cmbAssociationType.AddItem "TownHomes"
.cmbAssociationType.AddItem "Mixed"
.cmbAssociationType.AddItem "Condo"
.cmbAssociationType.AddItem "Commercial"
.cmbAssociationType.AddItem "POA"
.cmbAssociationType.AddItem "Villas"
.cmbAssociationType.AddItem "Other"
.txtUnitCount.Value = ""
.optFull.Value = False
.optActOnly.Value = False
.txtLastManagerChange.Value = ""
.txtCAMSenior.Value = ""
.txtAMSenior.Value = ""
.lstDatabase.ColumnCount = 13
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "125,60,55,25,40,50,50,60,25,45,40"
If iRow > 1 Then
.lstDatabase.RowSource = "Database!A2:M" & iRow
Else
.lstDatabase.RowSource = "Database!A2:M2"
End If
End With
End Sub
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
With sh
.Cells(iRow, 1) = iRow + 1
.Cells(iRow, 1) = frmForm.txtLegalName.Value
.Cells(iRow, 2) = frmForm.txtTransitionDate.Value
.Cells(iRow, 3) = frmForm.txtAccountID.Value
.Cells(iRow, 4) = IIf(frmForm.optCAM.Value = True, "CAM", "AM")
.Cells(iRow, 5) = frmForm.txtCurrentManager.Value
.Cells(iRow, 6) = frmForm.txtTransitioningTo.Value
.Cells(iRow, 7) = frmForm.cmbDivision.Value
.Cells(iRow, 8) = frmForm.cmbAssociationType.Value
.Cells(iRow, 9) = frmForm.txtUnitCount.Value
.Cells(iRow, 10) = IIf(frmForm.optFull.Value = True, "CAM", "AM")
.Cells(iRow, 11) = frmForm.txtLastManagerChange.Value
.Cells(iRow, 12) = frmForm.txtCAMSenior.Value
.Cells(iRow, 13) = frmForm.txtAMSenior.Value
End With
Set sh = ThisWorkbook.Sheets("New Entries")
'Will enter on top row but will then be overwritten
iRow = [Counta(New Entries!A)] + 2
'Will enter all data but in middle of table (mimics database positioning)
'Range("A" & Rows.Count).End(xlUp).Offset(1).Select
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 1) = frmForm.txtLegalName.Value
.Cells(iRow, 2) = frmForm.txtTransitionDate.Value
.Cells(iRow, 3) = frmForm.txtAccountID.Value
.Cells(iRow, 4) = IIf(frmForm.optCAM.Value = True, "CAM", "AM")
.Cells(iRow, 5) = frmForm.txtCurrentManager.Value
.Cells(iRow, 6) = frmForm.txtTransitioningTo.Value
.Cells(iRow, 7) = frmForm.cmbDivision.Value
.Cells(iRow, 8) = frmForm.cmbAssociationType.Value
.Cells(iRow, 9) = frmForm.txtUnitCount.Value
.Cells(iRow, 10) = IIf(frmForm.optFull.Value = True, "CAM", "AM")
.Cells(iRow, 11) = frmForm.txtLastManagerChange.Value
.Cells(iRow, 12) = frmForm.txtCAMSenior.Value
.Cells(iRow, 13) = frmForm.txtAMSenior.Value
End With
End Sub
Sub Show_Form()
frmForm.Show
End Sub
Below is the code that works perfectly well, except for the positioning of the "New Entries" worksheet table:
Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] 'Identifying the last row
With frmForm
.txtLegalName.Value = ""
.txtTransitionDate.Value = ""
.txtAccountID.Value = ""
.optCAM.Value = False
.optAM.Value = False
.txtCurrentManager.Value = ""
.txtTransitioningTo.Value = ""
.cmbDivision.Clear
.cmbDivision.AddItem "Brevard"
.cmbDivision.AddItem "Gainesville"
.cmbDivision.AddItem "Jacksonville"
.cmbDivision.AddItem "Ocala"
.cmbDivision.AddItem "Orlando"
.cmbDivision.AddItem "Sarasota"
.cmbDivision.AddItem "Tampa"
.cmbDivision.AddItem "Volusia"
.cmbAssociationType.Clear
.cmbAssociationType.AddItem "SFH"
.cmbAssociationType.AddItem "TownHomes"
.cmbAssociationType.AddItem "Mixed"
.cmbAssociationType.AddItem "Condo"
.cmbAssociationType.AddItem "Commercial"
.cmbAssociationType.AddItem "POA"
.cmbAssociationType.AddItem "Villas"
.cmbAssociationType.AddItem "Other"
.txtUnitCount.Value = ""
.optFull.Value = False
.optActOnly.Value = False
.txtLastManagerChange.Value = ""
.txtCAMSenior.Value = ""
.txtAMSenior.Value = ""
.lstDatabase.ColumnCount = 13
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "125,60,55,25,40,50,50,60,25,45,40"
If iRow > 1 Then
.lstDatabase.RowSource = "Database!A2:M" & iRow
Else
.lstDatabase.RowSource = "Database!A2:M2"
End If
End With
End Sub
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
With sh
.Cells(iRow, 1) = iRow + 1
.Cells(iRow, 1) = frmForm.txtLegalName.Value
.Cells(iRow, 2) = frmForm.txtTransitionDate.Value
.Cells(iRow, 3) = frmForm.txtAccountID.Value
.Cells(iRow, 4) = IIf(frmForm.optCAM.Value = True, "CAM", "AM")
.Cells(iRow, 5) = frmForm.txtCurrentManager.Value
.Cells(iRow, 6) = frmForm.txtTransitioningTo.Value
.Cells(iRow, 7) = frmForm.cmbDivision.Value
.Cells(iRow, 8) = frmForm.cmbAssociationType.Value
.Cells(iRow, 9) = frmForm.txtUnitCount.Value
.Cells(iRow, 10) = IIf(frmForm.optFull.Value = True, "CAM", "AM")
.Cells(iRow, 11) = frmForm.txtLastManagerChange.Value
.Cells(iRow, 12) = frmForm.txtCAMSenior.Value
.Cells(iRow, 13) = frmForm.txtAMSenior.Value
End With
Set sh = ThisWorkbook.Sheets("New Entries")
'Will enter on top row but will then be overwritten
iRow = [Counta(New Entries!A)] + 2
'Will enter all data but in middle of table (mimics database positioning)
'Range("A" & Rows.Count).End(xlUp).Offset(1).Select
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 1) = frmForm.txtLegalName.Value
.Cells(iRow, 2) = frmForm.txtTransitionDate.Value
.Cells(iRow, 3) = frmForm.txtAccountID.Value
.Cells(iRow, 4) = IIf(frmForm.optCAM.Value = True, "CAM", "AM")
.Cells(iRow, 5) = frmForm.txtCurrentManager.Value
.Cells(iRow, 6) = frmForm.txtTransitioningTo.Value
.Cells(iRow, 7) = frmForm.cmbDivision.Value
.Cells(iRow, 8) = frmForm.cmbAssociationType.Value
.Cells(iRow, 9) = frmForm.txtUnitCount.Value
.Cells(iRow, 10) = IIf(frmForm.optFull.Value = True, "CAM", "AM")
.Cells(iRow, 11) = frmForm.txtLastManagerChange.Value
.Cells(iRow, 12) = frmForm.txtCAMSenior.Value
.Cells(iRow, 13) = frmForm.txtAMSenior.Value
End With
End Sub
Sub Show_Form()
frmForm.Show
End Sub