+ Reply to Thread
Results 1 to 19 of 19

VBA to list rows with coloured/conditionally formatted cells

  1. #1
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    VBA to list rows with coloured/conditionally formatted cells

    Hi all,

    I have conditional formatting set up on a set of data (columns A-D, ~1000 rows) to colour certain cells in red. I need a VBA script (that will be incorporated into a macro) that will list the values in column 'A' of any row with a red cell in it at the top of column F. Some rows could have two red cells, but need to only be listed once. Additionally, if there are no red cells, it should show 'None'.

    I have a variation of this working already using data validation and 'circle invalid data', but I'm keen for it to work with conditional formatting if possible.

    Is anyone able to help me? I've attached an example of what I'm looking for.

    Thanks,
    Jamie
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    Please Login or Register  to view this content.
    Kind regards
    Leo

  3. #3
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Re: VBA to list rows with coloured/conditionally formatted cells

    Hi Leo,

    Thanks for your reply. That does work very well, but what I meant by the 'None' thing, is if there are no red cells at all in the range it says 'None' in cell F2. If there are red cells, only those ones would be listed. Do you think that's possible?

    Thanks,
    Jamie

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    Think of this

    Please Login or Register  to view this content.
    Kind regards
    Leo

  5. #5
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    Correction

    Please Login or Register  to view this content.
    Cheers
    Leo

  6. #6
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Re: VBA to list rows with coloured/conditionally formatted cells

    Hi Leo,

    Thanks, that's great. The only thing that I've noticed (my fault, didn't explain very well!) is that your script specifically looks for 'A', 'D' or 'F'. The values I used were just examples. In reality it will (hopefully) be able to find anything in a red cell, but the value in the red cell could be a lot of different things. Is there anyway of specifying by colour instead of value?

    Thanks,
    Jamie

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA to list rows with coloured/conditionally formatted cells

    Try
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Re: VBA to list rows with coloured/conditionally formatted cells

    Hi jindon,

    That seems to be bugging at 'If Evaluate(r.Address & fc.Formula1) Then'.

    Thanks,
    Jamie

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA to list rows with coloured/conditionally formatted cells

    No error for me
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    PHP Code: 
    your script specifically looks for 'A''D' or 'F'
    same condition as in conditional formatting, not ?

    you can change this part
    Please Login or Register  to view this content.
    to other conditions

    Cheers
    Leo

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA to list rows with coloured/conditionally formatted cells

    Quote Originally Posted by jamiem4 View Post
    Hi jindon,

    That seems to be bugging at 'If Evaluate(r.Address & fc.Formula1) Then'.

    Thanks,
    Jamie
    If you are running on different workbook with different condition(s) then
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66
    Hi Leo,

    How would I change it to match the conditional formatting formulae? All of my conditional formatting is in the formula format, but I can't work out how to integrate that into your script.

    Thanks,
    Jamie


    Quote Originally Posted by LeoTaxi View Post
    PHP Code: 
    your script specifically looks for 'A''D' or 'F'
    same condition as in conditional formatting, not ?

    you can change this part
    Please Login or Register  to view this content.
    to other conditions

    Cheers
    Leo

  13. #13
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    Use the same conditions in the if statement as in the conditional formatting

    if you have a file, i will do it for you


    Kind regards
    Leo

  14. #14
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Re: VBA to list rows with coloured/conditionally formatted cells

    Hi Leo,

    Here is your (edited) script that I am using:

    -----------------------------------------------------

    Range("I5", "I" & Cells(Rows.Count, 1).End(xlUp).Row).ClearContents
    arr = Range("C2", "G" & Range("C" & Rows.Count).End(xlUp).Row)
    ReDim sn(UBound(arr))
    For x = 1 To UBound(arr)
    If arr(x, 2) = "B" Or arr(x, 3) = "D" Or arr(x, 4) = "F" Then
    sn(i) = arr(x, 1): i = i + 1
    End If
    Next
    If i > 0 Then Range("I5").Resize(i) = Application.Transpose(sn)
    If i = 0 Then Range("I5") = "None"

    --------------------------------------------------------
    Here is the script I am using to set the conditional formatting:
    --------------------------------------------------------

    Range("G2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=NOT(AND(LEFT(G2)<>""0"",SUMPRODUCT(0+(ISNUMBER(0+MID(G2,ROW(INDIRECT(""1:""&LEN(G2)-1)),1))))=LEN(G2)-1,ABS(77.5-CODE(RIGHT(G2)))<13))"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
    End With
    --------------------------------------------------------------------------
    Please could you show me how to replace "arr(x, 2) = "B"" with the conditional formatting formula and I should be able to do the rest.

    Thanks,
    Jamie
    Last edited by jamiem4; 11-28-2016 at 02:32 PM.

  15. #15
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    maybe if i have the file with the working script

  16. #16
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Re: VBA to list rows with coloured/conditionally formatted cells

    Unfortunately I can't send the file due to the sensitivity of the data, and some of the other conditional formatting formulae used are also sensitive

  17. #17
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    it dont have to be THE file
    you can create 1

    cheers
    Leo

  18. #18
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Re: VBA to list rows with coloured/conditionally formatted cells

    Please find an example file attached.

    The aim is to have the corresponding values from column C of red cells in the 'Format Check' columns listed from cell I5 downwards.

    Hope that makes sense!

    Thanks,
    Jamie
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA to list rows with coloured/conditionally formatted cells

    This is a file where the script dont work

    i ame asking for a file with working script ( youre own script for conditional formatting)
    so the file i ame asking contains a few red marked cells


    cheers
    Leo

+ 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] Counting Conditionally Formatted Coloured Cells
    By Tiraenus in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-23-2018, 08:03 PM
  2. Counting coloured cells that are conditionally formatted
    By vmutch in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-24-2015, 02:46 PM
  3. [SOLVED] How to Sum cells that have been conditionally formatted
    By kbaz555 in forum Excel General
    Replies: 2
    Last Post: 08-25-2014, 12:24 PM
  4. [SOLVED] Copy conditionally formatted non-adjacent rows
    By Thistledown in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-12-2014, 09:31 AM
  5. [SOLVED] Sum of conditionally formatted cells by colour
    By codeyl5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2012, 09:42 AM
  6. Sum conditionally formatted cells
    By akabraha in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2010, 02:22 PM
  7. [SOLVED] Report for Conditionally Formatted Cells
    By Sige in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2005, 08:26 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