+ Reply to Thread
Results 1 to 8 of 8

VBA update search find routine using userform listbox selection

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    VBA update search find routine using userform listbox selection

    So someone recently helped me with implementing a way to manage data updates using a sheet change event within a lookuplist sheet and it works great...however only if the user updates values on the sheet directly. The goal is this list will be hidden and controlled using only forms allowing the user to work within the forms regardless of which sheet is selected. Many thanks to mart37 for the code:
    Please Login or Register  to view this content.
    When a value is updated (or added) when not on the lookup sheet, the error occurs on:
    Please Login or Register  to view this content.
    I've changed ActiveSheet to Sheets(5) - but I'm not sure if I'm referencing the sheets correctly. Regardless, it doesn't seem to make a difference.
    Last edited by terriertrip; 09-07-2017 at 04:33 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Worksheet change errors when macro changes values

    The Change event macro only works on the host sheet.

    If you want to use the macro to change another sheet then use the change event macro to call another macro.

    The Second Macro should be in a normal macro module.

    You can delete the Message Box, if that line is not needed.
    Last edited by mehmetcik; 09-05-2017 at 07:19 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Worksheet change errors when macro changes values

    I understand that the change event only works on the host sheet. The change is indeed made to the host sheet from the sub routine. It's when a change to the host sheet occurs, values are updated within another database within another sheet. Like I say, it works, but only if the host sheet is active. I guess I don't understand why the sheet needs to be active for the sub to fire properly. Is there an alternative, such as something in the update macro to activate the host sheet, make the update (or add), then reactivate whatever sheet the change was made from? Something like:
    Please Login or Register  to view this content.
    Could something like that work? Does it make any sense? Apologies for the simplicity, as I'm somewhat of a vba novice.

    UPDATE: so I ran the below code and it worked to update the host sheet without any error:
    Please Login or Register  to view this content.
    The value on the host sheet changed via the macro. Why is the worksheet change event not recognizing the value change even when the macro is run while the host sheet is active? It works when I change the value on my keyboard, but not through the form.
    Last edited by terriertrip; 09-05-2017 at 08:08 PM.

  4. #4
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Worksheet change errors when macro changes values

    Can anybody help me with this?

  5. #5
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Worksheet change errors when macro changes values

    Assuming that

    Please Login or Register  to view this content.
    is the problem area then try removing ActiveSheet so that line becomes:

    Please Login or Register  to view this content.

    Or try

    Please Login or Register  to view this content.
    Last edited by Cyclops; 09-06-2017 at 04:59 PM.

  6. #6
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Worksheet change errors when macro changes values

    That seems to work to solve the error. The worksheet change event does not fire when the change is made.

  7. #7
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Worksheet change errors when macro changes values

    Maybe the intersect is returning nothing?



    Change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.


    If you get the message boxes, it should clear things up. If you don't then it isn't triggering.

    If it's not triggering then I would make sure that events are enabled and that you are actually changing the cell. If it's a formula that references a cell on another sheet, changing the reference cell won't trigger the worksheet change event.

  8. #8
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    VBA update search find routine using userform listbox selection

    UPDATE: This is an update to my problem of updating a secondary data using an update to primary data value. Originally I was using a sheet update event, but decided that the easier solution would be to just put the code within the update routine. The title has been changed to reflect the issue. I thought maybe posting my solution may help others if they were ever so inclined to have the same issue. It is only for a command button, but I believe one can get the gist.

    The userform code allows updates to list of primary values (attributes) using listbox selection through text control. Range data are used to compile a secondary dataset within separate sheet, therefore can contain many copies of primary value within secondary dataset.

    When user updates original primary value through the listbox selection, dataset values compiled from the list are updated to reflect updated value. Below is final code.
    Please Login or Register  to view this content.
    Last edited by terriertrip; 09-07-2017 at 04:33 PM. Reason: simplified code

+ 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. [SOLVED] Form values not being added to worksheet-No errors
    By rob_h in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2017, 06:08 AM
  2. PivotChart macro, to display all field values, errors out on last value
    By darkorder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2016, 09:02 PM
  3. [SOLVED] Functional VBA code errors out when included in Worksheet.Change event
    By aquixano in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 09-21-2015, 12:20 PM
  4. Macro to change cell values based on changes in another worksheet
    By joee0201 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 03:29 PM
  5. Combo Box Form Control w/macro to change pivot table filters - Getting Errors
    By Nyolls in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2013, 05:37 PM
  6. Change colour of shape if there are any formula errors in worksheet
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-23-2010, 09:31 AM
  7. Code for button errors due to worksheet name change
    By ge0rge in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-15-2008, 12:22 PM

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