bjfulkerson
asked on
userform excel 2007, use ADD to update worksheets
I need the correct code to update a worksheet using cmdADD
Sheets("The sheet name").Range("A1") = "blah"
ASKER
Can you tell me what is wrong with this. It won't update
Private Sub cmdAdd_Click()
Dim lastrow As Long
lastrow = Sheets("WorkSheets").Range ("A2" & Rows.Count).End
Cells(lastrow + 1, "A").Value = ComboBox1.Text
Cells(lastrow + 1, "B").Value = TxtDate.Text
Cells(lastrow + 1, "C").Value = CB2FunctionCode.Text
Cells(lastrow + 1, "D").Value = TxtTime.Text
Cells(lastrow + 1, "E").Value = TxtUnits.Text
Cells(lastrow + 1, "G").Value = TxtFname.Text
Cells(lastrow + 1, "H").Value = TxtLName.Text
Cells(lastrow + 1, "I").Value = TxtHDept.Text
End Sub
Private Sub cmdAdd_Click()
Dim lastrow As Long
lastrow = Sheets("WorkSheets").Range
Cells(lastrow + 1, "A").Value = ComboBox1.Text
Cells(lastrow + 1, "B").Value = TxtDate.Text
Cells(lastrow + 1, "C").Value = CB2FunctionCode.Text
Cells(lastrow + 1, "D").Value = TxtTime.Text
Cells(lastrow + 1, "E").Value = TxtUnits.Text
Cells(lastrow + 1, "G").Value = TxtFname.Text
Cells(lastrow + 1, "H").Value = TxtLName.Text
Cells(lastrow + 1, "I").Value = TxtHDept.Text
End Sub
To determine the last available row, replace
or, if you know the data in column A is contiguous (no empty cells), then you can use:
I presume you have already defined and assigned the values in the objects listed later.
Regards,
-Glenn
lastrow = Sheets("WorkSheets").Range("A2" & Rows.Count).End
with lastrow = Sheets("WorkSheets").Cells.SpecialCells(xlLastCell).Row
or, if you know the data in column A is contiguous (no empty cells), then you can use:
lastrow = Sheets("WorkSheets").Range("A2").End(xlDown).Row
I presume you have already defined and assigned the values in the objects listed later.
Regards,
-Glenn
ASKER
Not sure what you mean by that.
It still is not updating
It still is not updating
Instead of "WorkSheets" use the name of a single worksheet like "Sheet1".
ASKER
Still no update
Private Sub cmdAdd_Click()
Dim lastrow As Long
llastrow = Sheets("Sheet1").Range("A2 ").End(xlD own).Row
Cells(lastrow + 1, "A").Value = ComboBox1.Text
Cells(lastrow + 1, "B").Value = TxtDate.Text
Cells(lastrow + 1, "C").Value = CB2FunctionCode.Text
Cells(lastrow + 1, "D").Value = TxtTime.Text
Cells(lastrow + 1, "E").Value = TxtUnits.Text
Cells(lastrow + 1, "G").Value = TxtFname.Text
Cells(lastrow + 1, "H").Value = TxtLName.Text
Cells(lastrow + 1, "I").Value = TxtHDept.Text
End Sub
Private Sub cmdAdd_Click()
Dim lastrow As Long
llastrow = Sheets("Sheet1").Range("A2
Cells(lastrow + 1, "A").Value = ComboBox1.Text
Cells(lastrow + 1, "B").Value = TxtDate.Text
Cells(lastrow + 1, "C").Value = CB2FunctionCode.Text
Cells(lastrow + 1, "D").Value = TxtTime.Text
Cells(lastrow + 1, "E").Value = TxtUnits.Text
Cells(lastrow + 1, "G").Value = TxtFname.Text
Cells(lastrow + 1, "H").Value = TxtLName.Text
Cells(lastrow + 1, "I").Value = TxtHDept.Text
End Sub
You have a typo in your code.
llastrow = Sheets("Sheet1").Range("A2 ").End(xlD own).Row
should be
lastrow = Sheets("Sheet1").Range("A2 ").End(xlD own).Row
If that doesn't work then please attach your workbook.
llastrow = Sheets("Sheet1").Range("A2
should be
lastrow = Sheets("Sheet1").Range("A2
If that doesn't work then please attach your workbook.
ASKER
Here you go
STL-Function-Analysis-2015.xlsx
STL-Function-Analysis-2015.xlsx
The workbook you provided has no code and no command button that I can find. Please save it as an xlsm file.
ASKER
Sorry I sent the wrong one.
STL-Function-Analysis-2015-V2.xlsm
STL-Function-Analysis-2015-V2.xlsm
Your button on the userform is named "ccmdAdd", it should be "cmdAdd".
You have some other problems. Be back in a minute.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just an FYI. In my version of Excel 2007, there must be a bug.
the cmdAdd is actually ccmdAdd.
After I changed that it worked.
Do I use UPDATE the same way
cmdUPDATE
the cmdAdd is actually ccmdAdd.
After I changed that it worked.
Do I use UPDATE the same way
cmdUPDATE
In my version of Excel 2007, there must be a bug.The only way the name of the control became ccmdAdd is if you or someone else typed it that way.
the cmdAdd is actually ccmdAdd.
Do I use UPDATE the same wayThat's really too broad of a statement to answer exactly, but probably, yes.
ASKER
I will ask a new question.
I'm glad I was able to help.
In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014