+ Reply to Thread
Results 1 to 13 of 13

Replace Part of Formula in Conditional Formatting

  1. #1
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Replace Part of Formula in Conditional Formatting

    Hi.

    I found a VBA sub on another site, but it is giving me an error. The string is from January, so I thought I would post it here for help with the error.
    https://superuser.com/questions/1765...d-the-year-202

    The error I receive is "Wrong number of arguments or too many property assignments"

    The ".Formula1=" in the For Each statement is highlighted when I click OK to the error.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Replace Part of Formula in Conditional Formatting

    That is a weird one ... I got it to work by cycling through the long-hand version rather than a declared FormatCondition, like this:
    Please Login or Register  to view this content.
    No clue why that works and the other one doesn't but perhaps it's a workaround for you. MM
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Replace Part of Formula in Conditional Formatting

    MatrixMan, thank you for your response.

    I still get the same error message and it highlights the entire line beginning ActiveSheet.

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Replace Part of Formula in Conditional Formatting

    I think you need to use the Modify method. Try something like:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Replace Part of Formula in Conditional Formatting

    Thank you for your response ByteMarks.

    I received the error "Method 'Modify' of object 'FormatCondition' failed" with the following line highlighted.
    Please Login or Register  to view this content.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Replace Part of Formula in Conditional Formatting

    Formula1 is read-only so the initial code shouldn't ever work.

    ByteMarks code should work, assuming the worksheet isn't protected.

    Just as a side note, not every item in the FormatConditions collection is actually a FormatCondition object, but you'd be getting a Type mismatch error if that were the problem.
    Rory

  7. #7
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Replace Part of Formula in Conditional Formatting

    Rorya, thank you for your response.

    The worksheet is not protected. I'm not sure why I'm getting the error.

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Replace Part of Formula in Conditional Formatting

    Can you post a workbook that demonstrates the problem? You can remove all the data.

  9. #9
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Replace Part of Formula in Conditional Formatting

    Here is a sample spreadsheet. I only added 1 conditional format on cell E27, that changes when E26 is changed to "Some Word". I entered all three code suggestions from this string to a module.

    Regarding the MatrixMan suggestion, I tried it exactly as supplied and also tried replacing the < & > with "Some Word" & "Sheet!$C$1" respectively. I wasn't sure what the < & > meant. Either way, I receive the same error message.
    Attached Files Attached Files

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Replace Part of Formula in Conditional Formatting

    The third version works fine here (though it won't do what you expect as the cell reference will be inside quotes).

    Tested on Mac and Windows M365.
    Last edited by rorya; 09-01-2023 at 09:33 AM.

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Replace Part of Formula in Conditional Formatting

    I got this to work, but the Replace operation seems a bit flaky even in the immediate window.


    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Replace Part of Formula in Conditional Formatting

    Thank you rorya. I still didn't get it to work, but having the word inside quotes does not work for my needs.

  13. #13
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Replace Part of Formula in Conditional Formatting

    ByteMarks, your revision worked for me. Thanks so much!

+ 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] Two-Part Problem - Complex Formula and Conditional Formatting
    By g.costapinto in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-14-2019, 05:22 AM
  2. Replies: 1
    Last Post: 03-06-2014, 07:14 PM
  3. How to replace part of a formula with VBA
    By rockfrawg in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-17-2014, 05:23 PM
  4. How do I replace part of a formula using VBA?
    By Vaslo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2012, 12:46 PM
  5. Modify Macro Search & Replace Formatting for part of cell
    By tkeiffer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2011, 05:48 PM
  6. Conditional Formatting Formula Help Part 2
    By RalphSE in forum Excel General
    Replies: 10
    Last Post: 05-03-2006, 07:50 PM
  7. [SOLVED] Search &amp;amp; Replace Formatting for part of cell
    By Tanya B in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2005, 09:05 AM

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