1 year ago
#389194
Samuel Lindemulder
Entering data from a userform to a table using first blank cell in a column
I want to enter data from my userform to a table. I foolishly thought I could do this the same way as when I entered it into a range. EDIT-my script actually does work to add the info to a table. I was mistaken. I also need to start my entry at the first blank cell in column A, and right now I have it set to the first blank row. I appreciate any help! Here is the code I have currently:
Option Explicit
Private Sub cmdfir_Click()
Dim lRow As Long
Dim lPart As Long
Dim ws As Worksheet
Set ws = Worksheets("PQR data")
'find first empty row in database
''lRow = ws.Cells(Rows.Count, 1) _
'' .End(xlUp).Offset(1, 0).Row
'revised code to avoid problems with
'Excel lists and tables in newer versions
lRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'copy the data to the database
With ws
.Cells(lRow, 1).Value = Me.cbodatecoated.Value
.Cells(lRow, 2).Value = Me.cbodatepacked.Value
.Cells(lRow, 3).Value = Me.cboline.Value
.Cells(lRow, 4).Value = Me.cbocustomer.Value
.Cells(lRow, 5).Value = Me.cbopartnumber.Value
.Cells(lRow, 6).Value = Me.cbopartrev.Value
.Cells(lRow, 7).Value = Me.cbopowdernumberused.Value
.Cells(lRow, 8).Value = Me.cbopowderlotnumber.Value
.Cells(lRow, 9).Value = Me.cboboxnumbers.Value
.Cells(lRow, 10).Value = Me.cbocont.Value
.Cells(lRow, 11).Value = Me.cbolight.Value
.Cells(lRow, 12).Value = Me.cboheavy.Value
.Cells(lRow, 13).Value = Me.cbofisheye.Value
.Cells(lRow, 14).Value = Me.cboseeds.Value
.Cells(lRow, 15).Value = Me.cbodirt.Value
.Cells(lRow, 16).Value = Me.cboorangepeel.Value
.Cells(lRow, 17).Value = Me.cbochemicals.Value
.Cells(lRow, 18).Value = Me.cbospits.Value
.Cells(lRow, 19).Value = Me.cboyarn.Value
.Cells(lRow, 20).Value = Me.cboscratch.Value
.Cells(lRow, 21).Value = Me.cbodrops.Value
.Cells(lRow, 22).Value = Me.cbotabs.Value
.Cells(lRow, 23).Value = Me.cboother.Value
.Cells(lRow, 25).Value = Me.cbometal.Value
.Cells(lRow, 26).Value = Me.cbopackedgood.Value
End With
'clear the data
Me.cboline.Value = 1
Me.cbocustomer.Value = "Gentex"
Me.cbopartnumber.Value = "350-0010-001"
Me.cbopartrev.Value = ""
Me.cbopowdernumberused.Value = "PY"
Me.cbopowderlotnumber.Value = ""
Me.cboboxnumbers.Value = ""
Me.cbocont.Value = ""
Me.cbolight.Value = ""
Me.cboheavy.Value = ""
Me.cbofisheye.Value = ""
Me.cboseeds.Value = ""
Me.cbodirt.Value = ""
Me.cboorangepeel.Value = ""
Me.cbochemicals.Value = ""
Me.cbospits.Value = ""
Me.cboyarn.Value = ""
Me.cboscratch.Value = ""
Me.cbodrops.Value = ""
Me.cbotabs.Value = ""
Me.cboother.Value = ""
Me.cbometal.Value = ""
Me.cbopackedgood.Value = ""
Me.cboline.SetFocus
End Sub
Private Sub UserForm_Click()
End Sub
excel
vba
userform
0 Answers
Your Answer