+ Reply to Thread
Results 1 to 10 of 10

VBA Extending Conditional Formatting Code

  1. #1
    Registered User
    Join Date
    08-24-2015
    Location
    Texas, USA
    MS-Off Ver
    365 MSO (16.0.x.x) 64-bit
    Posts
    15

    Question VBA Extending Conditional Formatting Code

    Unfortunately, I can't figure out a way to accomplish what I want using the Excel GUI. I'm curious if this can be done using VBA code? The code currently marks Duplicate entries in Column D. I'd like it to extend a border around the conditional formatted cell in Column D and the cell directly to its right in Column E. Is this possible?

    What The Code Does
    cf1.png

    What I Would Like The Code To Do
    cf2.png

    Please Login or Register  to view this content.
    Last edited by Mulsiphix; 08-30-2015 at 09:20 PM. Reason: Marked as Solved! Thank you 6StringJazzer!!!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA Extending Conditional Formatting Code

    It sounds like you want to write code to set up conditional formatting rules. If you can do it with code, you can do it within the Excel GUI. (An alternative is to use code to directly modify the formatting, but that is not what your code is doing.) What is the reason you want to do this in code, rather than just setting up the CF rules?

    Anyway, it is possible but it's a little tedious. Conditional formatting operates on a single cell, so you need one rule for when the row is the first of a series of duplicates, then another rule for if it's in the middle, and another rule for if it's last. And you need one set of rules for the first column, and another for the second if you do not want a line down the middle. So you need six rules. See attached for CF example. Do you need help translating this to code?

    Note: This doesn't work if the numbers in D are not grouped. That is, if duplicates are not consecutive it isn't going to work.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    08-24-2015
    Location
    Texas, USA
    MS-Off Ver
    365 MSO (16.0.x.x) 64-bit
    Posts
    15

    Re: VBA Extending Conditional Formatting Code

    I apologize for my late reply. I had some internet connectivity issues between paychecks.

    I'm writing a massive Macro in Excel so I need the conditional formatting process automated. If I knew how to do what you've done in your example using the GUI, I would try recording that with a macro. I just don't know how to use the GUI to accomplish my goal. I'm looking at the CF rules you created and it looks like you manually created a rule for each cell (as you described would be the case for VBA). Is this the case? If so, it doesn't look like this could be automated. That sucks but at least I will know it isn't possible . Thank you so much for your help
    Last edited by Mulsiphix; 08-29-2015 at 01:11 PM.

  4. #4
    Registered User
    Join Date
    08-24-2015
    Location
    Texas, USA
    MS-Off Ver
    365 MSO (16.0.x.x) 64-bit
    Posts
    15

    Re: VBA Extending Conditional Formatting Code

    whoops, double post

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA Extending Conditional Formatting Code

    Quote Originally Posted by Mulsiphix View Post
    ...it looks like you manually created a rule for each cell (as you described would be the case for VBA). Is this the case?
    Not exactly, I created a rule for each type of cell.

    You need two sets of rules. One set is for the cells in the left column, because those cells will not have a border on the right edge. The other set is for the cells in the right column, because they will not have a border on the left edge.

    In each set, you need three rules: One to apply to the top cell because it has no border on the bottom, for the bottom cell because it has no border on the top, and one for the middle cells because they have no borders on the top or the bottom.

    This code will create my rules:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-24-2015
    Location
    Texas, USA
    MS-Off Ver
    365 MSO (16.0.x.x) 64-bit
    Posts
    15

    Re: VBA Extending Conditional Formatting Code

    The code looks awesome . Although I just noticed a problem. I see that the formulas are detecting duplicates in both Columns. Duplicates only occur in Column D in my data. So highlighting the cells next to duplicate values in column D is impossible, right ? Here is an example of my data:

    example50.png

    The amount of data and ultimately how many rows it will take up will be different every time I execute this macro. So I need to modify the code to detect the range. I can figure out how to settle the variable cell number per column problem, but not sure how to apply HowMany to a formula, since its a variable.

    Please Login or Register  to view this content.
    I read your signature and saw the line about posting pictures, so I've attached my excel file. I'm working with the data located in the sheet "CF Testing"
    Attached Files Attached Files
    Last edited by Mulsiphix; 08-29-2015 at 05:43 PM. Reason: Complete rewrite, added my file

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA Extending Conditional Formatting Code

    Looking at my code, I see that the rules apply to columns A and B, looking for duplicates in D. That is an error, my apologies. In any event:
    Quote Originally Posted by Mulsiphix View Post
    The code looks awesome . Although I just noticed a problem. I see that the formulas are detecting duplicates in both Columns. Duplicates only occur in Column D in my data. So highlighting the cells next to duplicate values in column D is impossible, right ?
    The solution I provided looks only in column D for duplicates. If that is not what you are seeing then something was changed when you tried to implement my solution in your own file.

    Your description in your first post does not match the layout in the file you attached. So now I don't know where you are actually trying to look for duplicates. Your original description says to format columns D and E based on duplicates in column D. Your file looks like you need to format A and B for duplicates in A, and also C and D for duplicates in C.

    Here is the revised code that will format columns D and E based on duplicates in D as in your original. If your layout is different then we will have to update the code accordingly. Help me understand the actual target format and we can finish this up.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-24-2015
    Location
    Texas, USA
    MS-Off Ver
    365 MSO (16.0.x.x) 64-bit
    Posts
    15

    Re: VBA Extending Conditional Formatting Code

    Quote Originally Posted by 6StringJazzer View Post
    Looking at my code, I see that the rules apply to columns A and B, looking for duplicates in D. That is an error, my apologies.
    None are needed. I hadn't even noticed

    Quote Originally Posted by 6StringJazzer View Post
    The solution I provided looks only in column D for duplicates. If that is not what you are seeing then something was changed when you tried to implement my solution in your own file.
    I haven't worked with Excel formulas much. I did some googling for a refresher and then proceeded to misread your formulas and post my "discovery". I'm sorry about that.

    Quote Originally Posted by 6StringJazzer View Post
    Your description in your first post does not match the layout in the file you attached. So now I don't know where you are actually trying to look for duplicates. Your original description says to format columns D and E based on duplicates in column D. Your file looks like you need to format A and B for duplicates in A, and also C and D for duplicates in C.
    At one point I decided to see how my document would do if I combined columns C and D. I didn't like it. Though, yesterday, I managed to upload that version to you (hence there was no "CF Testing" page I had described previously). This was a huge mistake on my part and I apologize for the confusion.

    Quote Originally Posted by 6StringJazzer View Post
    Here is the revised code that will format columns D and E based on duplicates in D as in your original. If your layout is different then we will have to update the code accordingly. Help me understand the actual target format and we can finish this up.
    This works perfectly. Thank you so much for your help. I wish I could pay you back somehow . You are amazing!

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA Extending Conditional Formatting Code

    Glad to help! Next time I'm in Texas you can buy me some Texas barbecue

  10. #10
    Registered User
    Join Date
    08-24-2015
    Location
    Texas, USA
    MS-Off Ver
    365 MSO (16.0.x.x) 64-bit
    Posts
    15

    Re: VBA Extending Conditional Formatting Code

    Quote Originally Posted by 6StringJazzer View Post
    Glad to help! Next time I'm in Texas you can buy me some Texas barbecue
    You've got it

+ 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. Extending conditional formatting in combination met merged cells
    By jackhays in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 02-10-2015, 09:24 AM
  2. Replies: 5
    Last Post: 02-22-2013, 11:35 PM
  3. Conditional Formatting- extending to whole row
    By rhlongo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2010, 10:04 PM
  4. Conditional Formatting Code - Deletes Wrong Conditional Format
    By RSpecianJr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2010, 10:53 AM
  5. Replies: 1
    Last Post: 05-23-2009, 12:54 AM
  6. Extending VBA conditional formatting
    By alpha1980 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-29-2008, 07:55 AM
  7. Extending Conditional Formatting
    By SamuelT in forum Excel General
    Replies: 1
    Last Post: 02-12-2007, 04:36 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