Solved

userform excel 2007, use ADD to update worksheets

Posted on 2014-12-18
17
161 Views
Last Modified: 2014-12-18
I need the correct code to update a worksheet using  cmdADD
0
Comment
Question by:bjfulkerson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
17 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507563
Sheets("The sheet name").Range("A1") = "blah"
0
 

Author Comment

by:bjfulkerson
ID: 40507574
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
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40507586
To determine the last available row, replace
lastrow = Sheets("WorkSheets").Range("A2" & Rows.Count).End

Open in new window

with
lastrow = Sheets("WorkSheets").Cells.SpecialCells(xlLastCell).Row

Open in new window


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

Open in new window


I presume you have already defined and assigned the values in the objects listed later.

Regards,
-Glenn
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bjfulkerson
ID: 40507596
Not sure what you mean by that.

It still is not updating
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507669
Instead of "WorkSheets" use the name of a single worksheet like "Sheet1".
0
 

Author Comment

by:bjfulkerson
ID: 40507688
Still no update

Private Sub cmdAdd_Click()
   Dim lastrow As Long
   llastrow = Sheets("Sheet1").Range("A2").End(xlDown).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
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507703
You have a typo in your code.

llastrow = Sheets("Sheet1").Range("A2").End(xlDown).Row

should be

 lastrow = Sheets("Sheet1").Range("A2").End(xlDown).Row

If that doesn't work then please attach your workbook.
0
 

Author Comment

by:bjfulkerson
ID: 40507709
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507721
The workbook you provided has no code and no command button that I can find. Please save it as an xlsm file.
0
 

Author Comment

by:bjfulkerson
ID: 40507729
Sorry I sent the wrong one.
STL-Function-Analysis-2015-V2.xlsm
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507768
Your button on the userform is named "ccmdAdd", it should be "cmdAdd".
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507774
You have some other problems. Be back in a minute.
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40507795
After correcting the name of the button as I posted in post ID 40507768, use this code.
Private Sub cmdAdd_Click()
   Dim lastrow As Long
   
   With Sheets("Timesheet")
     lastrow = .Range("A1048576").End(xlUp).Row
    'lastrow = Sheets("Timesheet").Range("A2").End(xlDown).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 With
  
 End Sub

Open in new window

0
 

Author Comment

by:bjfulkerson
ID: 40507878
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
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40507905
In my version of Excel 2007, there must be a bug.
the cmdAdd is actually ccmdAdd.
The only way the name of the control became ccmdAdd is if you or someone else typed it that way.

Do I use UPDATE the same way
That's really too broad of a statement to answer exactly, but probably, yes.
0
 

Author Comment

by:bjfulkerson
ID: 40507916
I will ask a new question.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40508106
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question