+ Reply to Thread
Results 1 to 26 of 26

Update Existing Table with UserForm Values

  1. #1
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Update Existing Table with UserForm Values

    Hi, lost again,

    This is my largest VBA project so far and I'm still pretty new. I can't figure out how to update existing cell values in a sheet with the values entered into a userform. I'm grappling with the following Code:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Hi again,

    We don't use "SET" with regular variables (such as Strings, Integers, etc.), but only for objects (Workbook, Worksheet, Range, etc).
    Please Login or Register  to view this content.
    should just read
    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Hi again Arkadi,

    I made your edit to my code but now I get a Compile Error: Invalid Qualifier:

    Please Login or Register  to view this content.
    Thanks for all the help!

  4. #4
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Hey,

    I tried a different solution and it appears to be working. Thanks for the help! My new code is below:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    New Problem,

    Now when I run the UserForm I get a RunTime Error 13: Type Mismatch in the Change procedure for the ComboBox:

    Please Login or Register  to view this content.
    I tried changing the code so it did not rely on the Dynamic Named Range Lst_Locations, but now I get a Runtime Error: 1004; Method 'Range' of Object '_Worksheet' Failed:

    Please Login or Register  to view this content.
    Last edited by TFiske; 03-23-2018 at 01:04 PM. Reason: Updated with another attempt at code.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Sorry I didn't reply earlier, glad it works for you

    Please remember to mark the thread as solved? Thanks!
    Last edited by Arkadi; 03-23-2018 at 01:05 PM.

  7. #7
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Should I move my new problem to a new thread?

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Oh no sorry, didn't see the new post

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Can you upload a workbook?
    The second code you tried... have you given "lr" a value? It is an error that would happen (among other things), if lr was 0. It could also help to put ws. in front of "cells".
    Last edited by Arkadi; 03-23-2018 at 01:19 PM.

  10. #10
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Yes, I'll upload the project. See attached.

    as for lr:
    Please Login or Register  to view this content.
    It is showing up as the correct value of 55 in the Locals window.

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Byt the way:

    Please Login or Register  to view this content.
    errors because LocEdit is an array, get rid of ".Value" at the end and it would work fine.

  12. #12
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Thanks. I added "ws." in front of Cells in the Change procedure from eariler. The Error went back to Run Time Error 13: Type Mismatch

    Please Login or Register  to view this content.
    Last edited by TFiske; 03-23-2018 at 01:52 PM. Reason: Added Code Tags

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Ok, I see the problem... in your first version you use a named range, which is just column A, but your Vlookup asks to return the value in the second (or thrird, etc) column of the vlookup range.
    The same problem in your second version, but additionally, because the Locations sheet is not active, you have to put ws in front of cells when specifying a range (otherwise the active sheet is implied):

    Please Login or Register  to view this content.
    should be something like this:

    Please Login or Register  to view this content.
    I put the changes in red in the first line, but as you can see all lines need to change. Your newer version:

    ws.Range("A2", ws.Cells(lr, 1)), 2, False)

    won't work either, you would need ws.Range(ws.Range("A2"), ws.Cells(lr, 5
    Please Login or Register  to view this content.
    )), 2, False)

    Truth is that you could make that line lr,2 then the next line that wants the third column can be lr,3, and so on, but you need a vlookup range with at least as many columns as the column number you want the value for.
    Last edited by Arkadi; 03-23-2018 at 01:37 PM.

  14. #14
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    I'm still getting a Run Time Error 13:

    I tried your updated code with "ws." in front of all the cell references. I also tried creating a dynamic range "refRange" but I get the same error in the same place.

    Please Login or Register  to view this content.
    The error occurs after I've loaded the user form, edited values in the Edit Locations tab and clicked "Save and Edit Next".

    I really appreciate the help!!
    Last edited by TFiske; 03-23-2018 at 01:46 PM. Reason: gratitude

  15. #15
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Update Existing Table with UserForm Values

    Hi TFiske,

    Please fix post #12 with code tags.
    HTH
    Regards, Jeff

  16. #16
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Apologies. Fixed.

  17. #17
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Thanks for fixing that....

    Your problem is that once you blank the location after saving, the change code is triggered and the vlookup fails because the textboxes are blank.

    You may want to put

    If CmbBox_LocationEditSelect.Value = "" Then Exit Sub into the CmbBox_LocationEditSelect_Change() code:

    Please Login or Register  to view this content.

  18. #18
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Update Existing Table with UserForm Values

    Quote Originally Posted by TFiske View Post
    Apologies. Fixed.
    Appreciate it...

  19. #19
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Update Existing Table with UserForm Values

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  20. #20
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    That did it!! Thank you so much!

  21. #21
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    @bakerman2, showoff!

    Lol just kidding of course, good idea

  22. #22
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Update Existing Table with UserForm Values

    Backerman2, I tried you're code and I got a RunTime 13 at the same place.

    I added the Arkadi's if then check and it works aswell, see below:

    Please Login or Register  to view this content.
    But I will mark this as solved. Thank you all, again!

  23. #23
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    Glad we could help

  24. #24
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Update Existing Table with UserForm Values

    @ Arkadi

    Do you have a problem with me ?

    Also for performance better 1 Match then 4 Lookups.

  25. #25
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Update Existing Table with UserForm Values

    bakerman2, I was joking of course my friend... I thought your solution was very nice!

  26. #26
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Update Existing Table with UserForm Values

    @ Arkadi

    Nothing wrong with having some fun once and a while.

    @TFiske

    You're welcome and thanks for rep+.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform to Update Table Values based on a Listbox Selection
    By scottkelley80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-27-2016, 08:49 PM
  2. Unable to update the existing data with excel userform
    By Sanjibghosh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2016, 04:25 AM
  3. How do you update existing data in a table with an import?
    By rschoenb in forum Access Tables & Databases
    Replies: 3
    Last Post: 02-12-2015, 02:10 PM
  4. Replies: 3
    Last Post: 11-05-2014, 01:11 PM
  5. [SOLVED] Update an existing row with VB userform
    By amhulli in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2012, 03:32 AM
  6. Add to existing query, add table, update sum column
    By randell.graybill in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2011, 08:47 PM
  7. VB code to update existing Pivot Table
    By suzetter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2005, 06:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1