I have a spreadsheet that uses a userform to collect name & address (and other) data. The results from the input of the userform are added to the last row of a particular worksheet (See code below)
I now want to convert that worksheet into a table so that when another routine looks up data from that table (or its used in a combobox) it will always display what's in the table and not dependant on searching a range in the worksheet. I have the following code which puts the info onto the last row of a worksheet. How does this code need to change if I now convert the worksheet data into a table and have new info from the userform added to the last row of a table. Assume the table name is 'CustomerList'
Private Sub CmdAddAcct_Click()
Dim aiRow As Long
Dim wsh As Worksheet
Set wsh = Worksheets("Accounts")
'find first empty row in database
aiRow = wsh.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).row + 1
With wsh
.Cells(aiRow, 1).Value = Me.TxtNewName.Value
.Cells(aiRow, 2).Value = Me.TxtNewAcct.Value
.Cells(aiRow, 3).Value = Me.TxtAttention.Value
.Cells(aiRow, 4).Value = Me.TxtAdd1.Value
.Cells(aiRow, 5).Value = Me.TxtAdd2.Value & " " & Me.TxtAdd3.Value
.Cells(aiRow, 6).Value = Me.TxtPCode.Value
.Cells(aiRow, 7).Value = Me.TxtSSComment.Value
.Cells(aiRow, 8).Value = Me.TxtCIComment.Value
.Cells(aiRow, 9).Value = Me.LstType.Value
End With
Look forward to some help. With thanks
I now want to convert that worksheet into a table so that when another routine looks up data from that table (or its used in a combobox) it will always display what's in the table and not dependant on searching a range in the worksheet. I have the following code which puts the info onto the last row of a worksheet. How does this code need to change if I now convert the worksheet data into a table and have new info from the userform added to the last row of a table. Assume the table name is 'CustomerList'
Private Sub CmdAddAcct_Click()
Dim aiRow As Long
Dim wsh As Worksheet
Set wsh = Worksheets("Accounts")
'find first empty row in database
aiRow = wsh.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).row + 1
With wsh
.Cells(aiRow, 1).Value = Me.TxtNewName.Value
.Cells(aiRow, 2).Value = Me.TxtNewAcct.Value
.Cells(aiRow, 3).Value = Me.TxtAttention.Value
.Cells(aiRow, 4).Value = Me.TxtAdd1.Value
.Cells(aiRow, 5).Value = Me.TxtAdd2.Value & " " & Me.TxtAdd3.Value
.Cells(aiRow, 6).Value = Me.TxtPCode.Value
.Cells(aiRow, 7).Value = Me.TxtSSComment.Value
.Cells(aiRow, 8).Value = Me.TxtCIComment.Value
.Cells(aiRow, 9).Value = Me.LstType.Value
End With
Look forward to some help. With thanks