+ Reply to Thread
Results 1 to 7 of 7

Modifying a set of existing validation formulas

  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Modifying a set of existing validation formulas

    Good day. I have a list of 40 non-adjacent cells in a worksheet that contain validation formulas that include the MATCH function. I need to update the formula for each to include an additional MatchType in the formula string. Each formula is identical except for the Lookup_value, which is always a cell reference two cells above the cell containing the validation formula to be updated. I have created the code below via macro recording that will update the validation formula as needed, but its a full replacement and I will have to replicate it 40 times. Is there a method by which I can loop through each cell that has the validation formula and simply modify the existing formula in each without the full scale 'delete and add' approach I've created below?

    Many thanks for any assistance or guidance you can provide. Existing code as follows:


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Modifying a set of existing validation formulas

    You could use a code like this:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Modifying a set of existing validation formulas

    Thanks much, Antonio. This will streamline things considerably!

    When executing, I receive the run-time error 91: "Object variable or With block variable not set." I have declared r As Long, but am I missing a set statement somewhere....or is this referring to something else I've missed?

    Matt

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Modifying a set of existing validation formulas

    Probably it is necessary to use:

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    If you can please attach a little example of your file.

    Regards,
    Antonio

  5. #5
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Modifying a set of existing validation formulas

    Thanks Antonio. I tried adding the suggested code with no success. As requested, I've attached a test file with the code resident in Module 1. When executed it results in the same error code I'm receiving: run-time error 91: "Object variable or With block variable not set."

    Thanks again for your assistance.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Modifying a set of existing validation formulas

    I correct the code, now seems working fine.

    This is the code:
    Please Login or Register  to view this content.
    Regards,
    Antonio
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Modifying a set of existing validation formulas

    Thanks, Antonio. I think I may have made the attached spreadsheet example too simple. As you can see from the original code above, the validation formula needs to be dynamic rather than static...meaning the drop down list it displays must change based on the value in the cell two cells above it. Hence my use of the =CHOOSE(MATCH... function in the validation formula. In the spreadsheet example I attached previously, it means for example that the contents of cell F20 can change between TypeOne, TypeTwo or TypeThree depending on user input, and the formula for the drop down list in cell F22 must account for this variability. This is so for every 32nd cell beginning with F22 through F1270.

    Please Login or Register  to view this content.
    In this example, assume the TypeOne and TypeTwo range names have already been created and are in use in the existing validation formula. The purpose of my code is to go into the validation formula and add the range name TypeThree so that its contents will also be made available in the drop down list in F22 when TypeThree appears in cell F20, such that when the contents of cell F20 change, the contents of the drop down list selection in F22 change. This presumes that the range name TypeThree has already been created in the spreadsheet so it is a valid range.

    Again, the validation formulas for each of the 40 cells between F22 and F1270 are identical except for the cell address being referenced by the MATCH function (cell F20 for cell F22, cell F52 for cell F54, etc.).

    I still receive the run-time error 91: "Object variable or With block variable not set."

    Let me know if this further explanation helps.

    Matt

+ 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. Modifying existing code to save worksheet
    By Woopwoop in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-26-2015, 08:54 PM
  2. Modifying existing code
    By rhouston08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2015, 06:03 PM
  3. Modifying an existing excel time formula
    By spittingfire in forum Excel General
    Replies: 0
    Last Post: 02-03-2015, 10:04 PM
  4. [SOLVED] Add two more columns, modifying an existing VBA code help.
    By Anka in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 02-17-2013, 01:24 PM
  5. Help modifying macro to wrap iferror formulas around existing formulas
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:04 PM
  6. Help modifying existing VBA code
    By camcafe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2008, 11:02 AM

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