+ Reply to Thread
Results 1 to 51 of 51

Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

  1. #1
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Can we Get/Apply the Information of the Conditional Formatting used in any cell using VBA?

    Dear Forum,

    In one of my recent posts, I received help in getting the information of the Formula, Value and various aspects of Formatting..
    However, is it possible to get the information for the Conditional Formatting which is applied in the cell whose information I seek..

    Like for Example :

    I need to find the information for a particular cell which has a conditional formatting such as if the value contains the number between 0-25 then the Font Colour is RED , if the value is 26-50 then Orange and if the Value is 51-75 then Green and if the last range 76-100 is Blue.

    Now I know how to apply the same using conditional format dialog box manually however I need to extract this information from an already existing conditionally applied cell..as Information as well as I should be able to replicate this same information to a different Sheet using VBA..

    Warm REgards
    e4excel

  2. #2
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Dear Forum,

    One more thing I am also looking to get the information for the Borders used in the original Sheets data range to be replicated in the different sheet using this information...

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Maybe something like this would work for border info.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Hey Thanks Steven again,
    I had not checked this thread as busy on the other one.
    But please explain certain things in the Values used in this..

    Please Login or Register  to view this content.
    Do u mean ?
    7 = No of Columns and 12 = No of Rows in consideration
    then what is 1 to 3, Is it the three aspects such as .LineStyle , .Weight and .Color ?
    Are there are any other aspects in the BORDERS which I am missing?

    I was trying to use your Loop to get information for each aspect and then again use it in the "Dump" Sheet so the information for each cell in consideration was stored in the cell FORMATTING and the actual FORMATTING will be used in the DUMP sheet where I am simply trying to use the same formatting used in the REPORT sheet.

    My main aim is to have all the information of the Main SHeet be it the regular FILL COLOR, FONT COLOR,FONT SIZE, BOLD, UNDERLINE, ITALIC, ALIGNMENT and ALSO PATTERN COLOR AND BORDER COLORS as in this case.

    Also would like to know that when we have used the conditional formatting in any cell then the color value for those cells do not get captured normally as you have shown, is there any other way of doing it?

    Example:
    If a cell has a Font Color red due to a conditional formatting applied on the cells value can we record just the value for the RED Color for the Font..
    Last edited by e4excel; 06-19-2012 at 03:01 AM.

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    The following values are:

    7 = xlEdgeLeft
    8 = xlEdgeTop
    9 = xlEdgeBottom
    10 = xlEdgeRight
    11 = xlInsideVertical
    12 = xlInsideHorizontal

    So, to set the left edge of a border you can:

    Please Login or Register  to view this content.
    The values of edge left to inside horizontal are 7 to 12, and so it is possible to use numbers instead of the name, which allows me to create a loop.

    then what is 1 to 3, Is it the three aspects such as .LineStyle , .Weight and .Color ?
    That is where I decided to store the values of .LineStyle , .Weight and .Color.

    Please Login or Register  to view this content.
    This is just a two dimensional array. 7 to 12 was used in the first dimension because they correspond to the values belonging to the Border. 1 to 3 in the second dimension are arbitrary, I needed three slots to read & write values.

    Are there are any other aspects in the BORDERS which I am missing?
    There is also: 6 = xlDiagonalUp

    But when I added it, it created a diagonal line in every square even though it wasn't part of the original format.

    It is also possible to use ColorIndex instead of Color, but I've found that ColorIndex is less precise than Color.
    Last edited by StevenM; 06-19-2012 at 06:59 AM.

  6. #6
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    If a cell has a Font Color red due to a conditional formatting applied on the cells value can we record just the value for the RED Color for the Font..
    Yes, that is easy. But I would have assumed that you wanted the conditional formatting applied rather than just the color. And I'm unsure how to do that.

  7. #7
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Thanks a lot Steven for all the explanations..
    You know your posts are really very informative and I am actually learning a lot from them, of which I am able to also reproduce.
    Normally if the VBA code is tough then though I use it I find it difficult to add to it later....
    Let me mention that you have a nice style of writing the VBA code which even a formula person like me feels easy to understand.

    Thanks again..

    Ok Understood now that the numbers 7 to 12 stand for the various sides of a cell, but just out of curiosity, why it did not start from 1, then what does 1 to 6 or 5 stand for?
    And also as you mentioned that the 6 = Diagonals Inside.
    I as trying to do it manually for me to understand each different Border Aspect but when I tried for the Diagonals Up and Down it gave me the Diagonal Lines though it was not present in the original..
    How do I get what is there in the original to be reproduced in the "Dump" Sheet and nothing more nothing less.

    Now regarding, the conditional formatting my intention is to get the information of the conditional formatting used, but if that is difficult then I am willing to settle for even the formats which are used as ultimately I wan the formats to be used in the Dump so getting the values of the applied color also would be good though getting the information of the conditional formatting is also of paramount importance.
    Last edited by e4excel; 06-19-2012 at 09:35 AM.

  8. #8
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Let me mention that you have a nice style of writing the VBA code which even a formula person like me feels easy to understand.
    Thank you. That is, of course, intentional. And I worked hard to develop that style. Although, as a Chess Coach I'm used to taking complex ideas and expressing them so that those with less experience can understand them.

    Ok Understood now that the numbers 7 to 12 stand for the various sides of a cell, but just out of curiosity, why it did not start from 1, then what does 1 to 6 or 5 stand for?
    How do they say this: "It is outside my pay grade." :-)

    What I did was this. I recorded a macro where I applied borders to a region. Then I looked at the recorded code and played around with it. As I played around with it, I made the discoveries which I illustrated in my previous message. But to be honest, that is the limit of my knowledge. I don't know any more than what I showed you.

    it gave me the Diagonal Lines though it was not present in the original..
    I stated as such in my previous post. So I think my procedure has limitations and isn't foolproof.

  9. #9
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Hi StevenM,

    Thanks for the response, I tried the code it does make the Borders but somehow strangely the colours are getting interchangedTHe color for the Inside Verticals and Inside Horizontals are getting interchanged..

    Can you please help me with , getting the colour for the conditional formatting used..
    Is it different than what you ave helped in the earlier query

    Yes, that is easy. But I would have assumed that you wanted the conditional formatting applied rather than just the color. And I'm unsure how to do that.
    If the latter is not possible then can I just get the color information for a cell which has derived the color FillCOLOR and FONT color FONT size any such changes which can be possible due to conditional formatting..

    Thanks in advance..

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    do you want to know what format conditions have been assigned to a cell, or which formatting has actually been applied based on the conditional formatting criteria? the latter is extremely difficult in versions prior to 2010.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  11. #11
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Hi Joseph,

    Actually both, but if the latter is extremely difficult then just getting the information would be fine, but then let me just confirm one thing..
    In certain cells we have a default Fill Color, Font Color , Font Size and on the conditional formatting condition meeting the appearance changes so will it give me the information of the existing color or the color which is got changed due to the conditional formatting.

    Thanks in advance

  12. #12
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Okay, I think I've solved the problem of formatting conditions.

    Take a look at: e4excel_CreateTable_v2.xlsm

    And run: Run_CreateTable

    I realize that you have said you don't like this approach, but perhaps you can adapt from my code what you need.

    There is one mistake:

    Please Login or Register  to view this content.
    The first apostrophe in the above line needs to be deleted. It turns the font color white, and before I added the conditional formatting, a white font on a white background looks blank.

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    the properties in VBA will reflect the manually applied formatting and not the formatting applied by conditional formats. the only way to get the displayed format is to check all the format conditions and evaluate if each one's criteria are met; you may or may not then have to aggregate the formats of different conditions.

  14. #14
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    No Steven,

    I think you have already helped me getting the information of the regular Formatting and the Formula from the original sheet, now if I want to create an exact replica sheet like the "Report" then I want to use the same information which you help me get earlier..

    So, I am not writing the same information in the VBA code again but the earlier code helps me get and then I create the New Sheet with all the same details except the formula, after using it..
    What I mean is I derive the answers in the new sheet as if I were doing in the original sheet but after the answers are derived they would converted into Values..

    I think You have already helped on this part very well..now I just needed to get the information for the colors which are applied through formatting.
    Actually I dont mind even if I dont get the information the way we get it for the formula used in a cell.. so much but I need to get the Color Information in a cell like if the default cell fill color is red but due to conditional formatting it has changed to blue then the VBA code should acquire the information such as the .Color or .ColorIndex no for the bLue color..

    I liked the last file too and I definitely going to study the same..
    Last edited by e4excel; 06-20-2012 at 04:02 AM.

  15. #15
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    The only thing I do not follow is when I tried to get the information for the cells with no BORDERS i.e cells selected with FORMAT - BORDERS - NONE but they still produce a regular border.
    I want the code to record some value which means that there is no BORDER

  16. #16
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    So that was the flaw in my code, but the following corrects that.

    Please Login or Register  to view this content.
    My assumption is that if you add .weight or .color to a border, it will add a default line style. But if you check if the line style is = xlLineStyleNone before, you can stop the code from adding a border.

  17. #17
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Thanks Steven very sweet of you to reply so quickly actually I was searching for the condition to check whether it .xlLineStyleNone when you replied..
    One more thing , I am using your code but in the old style from the first help..

    Can you please help me on the same, a I have yet to use the above new approach, I mean i m going to use it later on but I started with the old approach..

    Please Login or Register  to view this content.
    This was to display..
    and this is to actually format the new sheets border based on the REPORT Sheets Border style.

    This line gives me the FOrmatting but how do i check whether it is NONE or not?
    Please Login or Register  to view this content.
    How do I write the NOT condition in the above line..

    And also, while researching I found out that there are several other aspects about Line Borders which are also important such as the below:

    Please Login or Register  to view this content.
    Thanks in advance..

  18. #18
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    An If statement is a true or false statement. A not negates a Boolean statement or variable.

    So maybe something like:

    Please Login or Register  to view this content.
    Or

    Please Login or Register  to view this content.
    Or something like that.

  19. #19
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Any Ideas on the below:
    'XlLineStyle can be one of these XlLineStyle constants:
    'xlContinuous
    'xlDash
    'xlDashDot
    'xlDashDotDot
    'xlDot
    'xlDouble
    'xlSlantDashDot
    'xlLineStyleNone


    'XlBorderWeight can be one of these XlBorderWeight constants:
    'xlHairline
    'xlThin
    'xlMedium
    'xlThick

    'The color is specified as an index value into the current color palette, or as one of the following XlColorIndex constants:
    'xlColorIndexAutomatic
    'xlColorIndexNone

  20. #20
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Thanks it worked like a charm, I was not able to use it for such a longtime as I made a mistake in your code.. by putting an "." before xlLineStyleNone
    My mistake..

    In most of my work I have used Dotted Lines as well as does that mean when I am considering these different aspects then i need to also consider the different sides too for each aspect..

  21. #21
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Try this.
    It collects all the information for borders for each cell.
    Then it recreates those borders.

    In the line:
    Please Login or Register  to view this content.
    The first range already has a border.
    The second range will copy the border info of the first range.


    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Wow Steven,

    You just are amazing man, I am getting more than I can chew..
    Seriously, not only was I getting to terms with your earlier help that you came up with such a Blinder..
    I mean this is what I would do if I knew VBA, you have done it so simply just put two ranges one after the other..such as in-built function..

    Thanks a lot..

    By the way I realized one thing that its not required to specify the other aspects such as Dotted or Dash as it gets automatically inherited from the parent Range..

    By virtue of so many solutions the thread should be closed I am so dying to do that as happy with so many different solutions but just one thing remaining to know if thats still a possibility..

    Conditional Formatting information for the applied color and not the Formula..
    I am just reiterating that I would be happy if I could just get the Color or COlorIndex , Fill COlor, Font Size:- No(s) or any other aspect which conditional formatting can influence i.e superficial color no derived from conditional formatting..

    So if a cell has a default black font color and the conditional formatting renders it a REd color then can I get the answer as the COLOR or COLORINDEX NO for RED color and not BLACK..

    Thanks in advance..

    Please let me know if thats possible or else this thread is SOLVED...

    Last edited by e4excel; 06-21-2012 at 02:04 PM.

  23. #23
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Conditional Formatting information for the applied color and not the Formula..
    I am just reiterating that I would be happy if I could just get the Color or COlorIndex , Fill COlor, Font Size:- No(s) or any other aspect which conditional formatting can influence i.e superficial color no derived from conditional formatting..

    So if a cell has a default black font color and the conditional formatting renders it a REd color then can I get the answer as the COLOR or COLORINDEX NO for RED color and not BLACK..
    I'm not for sure what you're asking.

    As for Color & Colorindex, I suspect that Color will always be more precise and that one shouldn't use colorindex. But I could be wrong.

    I don't have a lot of experience working with color formatting. I've worked on two workbooks with it, yours and one other. In that other workbook, I just copied the color formatting, and pasted it into another cell. So really, everything I know has been by playing around with your workbook.

    In the file you uploaded, the color formatting was a phrase plus an interior color. The way I understood it, the color of the font was just the property of the cell, but perhaps I could be wrong about that. Hmm ... I just ran a test, and I was not able to pick up the font color from the formatting. So unless I made a mistake, I was right. The font color was separate from the conditional formatting.

    No doubt conditional formatting can be more complex than what is in your workbook. But in your workbook, the color formatting was 4 sets of a phrases and interior color for each phrase. It would be easy to retrieve that information and store it as needed.

    I did a Google and found: http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx
    I have no idea if it will help you or not.

  24. #24
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Quote Originally Posted by StevenM View Post
    I'm not for sure what you're asking.

    As for Color & Colorindex, I suspect that Color will always be more precise and that one shouldn't use colorindex. But I could be wrong.

    It would be easy to retrieve that information and store it as needed.

    I did a Google and found: http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx
    I have no idea if it will help you or not.
    Thanks Steven,

    I am looking at the link its indeed very useful...

    My aim is to create a replica of the original Sheet skimming it of any formulas and keep it only values and also it should not contain any conditional formatting codes but the cells should still bear the same effect..

    When I am replicating the SHeet if in the cells where there is Conditional FOrmatting applied and if there is default No Fill or No Color for the Fill COlor and Font Color then what happens in the replicating sheet the text is not seen as its in white color and also the Fill Color is also white which means that the information that we derive using the below is doing so and getting the information for the default color its not really getting the info of the color which the CF is rendering it..

    I just need the ColorNo or ColorIndexNo whichever is accurate but for the color in the cell which is physically seen...
    Ex: by default there is No fill for both FOnt and Fill Color but when the CF is met the Fill Color is Dark Yellow and the Font Color is Dark Red, so I need to get the numeric values for Dark REd for the Font and the Dark Yellow for Fill Color..
    I dont care if I dont get the code used the way we kept a record of the cell formula but I need to have its utility by getting this info which will be simply used when the new sheet is created with the same data.

    Please Login or Register  to view this content.
    Since I am still new to VBA I am still using from the first help that you provided..

    Please tell me am I making mistake in the above lines or is there some different code which needs to produce the result?

    Thanks..in advance
    Last edited by e4excel; 06-22-2012 at 03:44 AM.

  25. #25
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Hi Steven.

    If thats possible please let me know, so that I can close the thread.
    The problem is that when I replicated the Report sheet which has default FOnt and Fill Color as NO COLOR it just pastes the contents with the same default color ignoring the COnditional Formatting which is rendering different FOnt and Fill colors based on the contents in the cell.

    Thanks in advance

  26. #26
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    I don't think I know anything on this issue more than what I've already posted. Frankly, it has been a learning experience for me, and I thank you for that. I've learned a lot playing around with your spreadsheet and exploring these issues. But I've never understood exactly what you were doing, or why you wanted to do it the way you are doing it. If I felt that I could help you again in some small way, you know I would. My non-response is merely due to the fact that I've exhausted all my knowledge on this issue and I don't think I have anything to add. As for the code you posted, how would I know if it worked or not? I can't just read code and know what it will do. As my bio makes clear, I don't claim to have anything more than a rudimentary understanding. While I'm willing to share my rudimentary understanding when I can, time and time again I've seen others post code far superior to mine.

  27. #27
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Yeah but those codes are so superior that I find it too difficult to extend or add to it and therefore I liked your approach simple yet can be improvised.
    Actually I making some Sheets where I need to get the replicas but when I tried just copy pasting it worked but it takes too much time and I think this approach is better to re-create a sheet using everything as if formulas and the decided formatting and then just convert it into values.

    It saves on time and the coding does not get revealed..

  28. #28
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Dear Forum,

    I found a link for my problem where I need the color codes for cells filled with conditional formatting.
    There's a link but I have some issues with my Download mgr and unable to do so..
    Can someone please try downloading and pasting it here as I can download from the forum without any hassles.

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=190

    Thanks

  29. #29
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Dear Steven,

    I found this code in the earlier link, now how I use this code over your code whenever there's a conditional formatting applied, I mean that I dont want to specify which cells has conditional formatting or not whichever has it they need to use this code and dont then your code and the color code should be derived..

    Please Login or Register  to view this content.

  30. #30
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Oh I am sorry it works for both normal cells with or without conditional formatting..
    But somehow its bot giving the right formatting when Im applying the color code

    But the only problem is that how do use it in this format?

    Please Login or Register  to view this content.
    Is the above style which you provided..

    Please Login or Register  to view this content.
    Thanks in advance
    Last edited by e4excel; 06-24-2012 at 09:40 AM.

  31. #31
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    its not working at all..

  32. #32
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Are you using the same workbook as before? (If so I have a copy of it.) If not, can you upload your workbook?

  33. #33
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Yeah the same one from the other query where you helped

  34. #34
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    So can you post the whole code, and point out which part is giving you problems?

  35. #35
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Yeah, actually I was trying to do that but every time I am doing that my nets going bad..
    Sorry...

    Please Login or Register  to view this content.

  36. #36
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Theres no error which is being thrown but inspite of using the Function ConditionalColor its not working and the Column D in the Dump SHeet remains without any color..

    SO I want you to please correct me where I am mistake in entering the code for FOnt and Interior in the lines where the coloring happens for the Dump Sheet

  37. #37
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Please correct the code wherever neccessary

  38. #38
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Where did you get the function ConditionalColor? It wasn't part of the code you posted.

  39. #39
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    PLease check post 29 , 28 and I have pasted the code in modules in my file

  40. #40
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    I reckon you ought to have a look at Chip Pearson's site: www.cpearson.com
    it has sample code for evaluating conditional formats (as long as you are using simple conditions you could use in 2003 and earlier). note the warnings about relative formulas.

  41. #41
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Theres no error which is being thrown but inspite of using the Function ConditionalColor its not working and the Column D in the Dump SHeet remains without any color..

    SO I want you to please correct me where I am mistake in entering the code for FOnt and Interior in the lines where the coloring happens for the Dump Sheet
    First of all, your conditional formatting doesn't have a font color. I believe I had mentioned this before.

    Run the following code on your worksheet.

    Please Login or Register  to view this content.

  42. #42
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Dear StevenM,

    First of all, your conditional formatting doesn't have a font color. I believe I had mentioned this before.
    I think I have made changes in the file and as my PC and net is slow and am not able to trace the old file, however I am uploading the File in contention to save trouble..

    I have made a few changes in the File..
    There are 4 Sheets:
    1 Data
    2 Report
    3 Formatting Information - This is used to store the information of the Range
    4 Replica - This is to create the replica of the Report Sheet.

    In the Replica, everything gets written i.e the contents the Regular Formats like Font Color which is done Manually in the Report sheet except for the column D where there's conditional formatting used..
    The contents do get copied but do not get displayed, strangely they have a White Font Color and the same regarding the Fill Color..there's no change in that though there are 5 different Conditional Formats set in the Report Sheet.

    I liked the last solution, I mean its so good that I think one doesn't need to even specify the range, however how do I use that in my case..

    Please advise on the same..
    Thanks in advance..
    Attached Files Attached Files

  43. #43
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    I mean its so good that I think one doesn't need to even specify the range, however how do I use that in my case..
    You must supply the function GetFormatConditions with at least one cell within the range which has format conditions. Then from that one cell, it can pick up all five conditions.

    The function returns a string with three items for each condition: (a) Formula1, interior color and font color. So with format conditions more complex than that, my code will be inadequate.

    Also note, Formula1 cannot contain a comma, because I use a comma as a marker in the string. (Of course, if a comma is used in Formula1, my marker can be changed.)

    The string is returned with two types of markers: (1) vbCr is used to separate the different format conditions, and (2) a comma is used to separate each element in a condition.

    Please Login or Register  to view this content.
    Of course, you need to replace "Formula1, Interior Color, and Font Color" with where ever you want to write these values.

  44. #44
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Dear Steven,

    May I please request you to add the two codes and then upload an attachment..
    I am not able to follow what and where I need to make the additions with your code as well as the code which I mentioned in the Post # 29 and the link for the same in the Post # 28..

    Are these the lines where I need to make the additions :
    Please Login or Register  to view this content.
    So humble request upload the Sheet where you have made the changes as well as see the other code if thats more superior in terms of handling more criteria not that your code isn't it..
    I honestly liked your code as it mentions the condition criteria and then the FOnt Color and Interior Fill COlor but as far as this requirement goes I would need just the Color Code(s) for Font as well as Fill Color..

    Please Login or Register  to view this content.
    So please thanks in advance..

    Warm Regards
    e4excel

  45. #45
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    What part of my last message did you not understand?

  46. #46
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Hi Steve,

    Honestly, I thought that the last post #43 contained the code from the actual excerpts from the function but now after re-reading your post several times I realized that I missed that as a part of the Function..

    I am not so familiar with VBA and the last 2-3 codes and functions are a little too heavy for me..I mean i have not understood them completely but still get the results well but when it comes to applying it does reveal my folly..

    Uptill now I was just asking , if it was possible to get the formula of the conditional formatting but I think you have already made provisions for the same..

    I dont have anything as Formula1 till now, I mean I have the cell formula in my code which you had provided which gives the formula in the cell but now that is already happening the things remaining were the Font Color and Fill Color or the Interior Color incase of the Conditional Formatting Applied Cells..

    Please Login or Register  to view this content.
    Just to confirm that I need to add those lines in the Code in the Sheet Formatting instructions Right?

    Please Login or Register  to view this content.
    Like this nah..

    Warm regards
    e4excel

  47. #47
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Quote Originally Posted by StevenM View Post
    What part of my last message did you not understand?
    Dear Steve,

    Sincere apologies, but believe me
    Though I like all your solutions/codes provided till now it still is difficult for me to really adapt so fast..
    So please please forgive me for that..

  48. #48
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    I still don't know what you are asking.

    The function I wrote: GetFormatConditions collects thee items from format conditions: (a) Formula1, (b) interior color, and (c) font color.

    I would assume that format conditions can get more complex than that, so if you need more information than that, my GetFormatConditions function won't be of much use. But it seems to me that this might be acceptable for your use.

    One of the problems is that a cell can contain more than one format condition. And my function returns them all.

    But it returns them all in one long string. I don't know what your needs are, nor what you are trying to accomplish.

    In your last workbook, you had five format conditions, and with three items per each, that is 15 pieces of information (all in one lone string).

    As I tried to illustrate in message #43, there is a simple way of getting to this 15 pieces of data by using the Split function. The first split divides the string in 5 parts (based on 5 formatting conditions). The second split divides each of the 5 parts into three parts: (a) Formula1, (b) interior color, and (c) font color.

    So if you want to write their information into a cell, one cell for each item, then you have to loop.
    Maybe something like:

    Please Login or Register  to view this content.
    You need to modify Cells, nRow, nCol to suit your needs.

  49. #49
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Now I actually could understand some part of it, really appreciate your patience with me..
    How the code was working..

    But I am still lost ,as though your function is extremely useful I am not sure how to go about further?
    I was even trying to integrate the values from the other function but in vain..

    I think all the major part is over except the tail..

    What I am asking is? In the uploaded File , if you click the command button in the Formatting Information Sheet, it goes to the Replica Sheet and starts creating the exact replica however in the column D though the values appear they do not get displayed as the Font is White or No Color..
    I only want this to have the same color as the Parent Sheet REport Colund, In the Parent sheet the colors are rendered by applying conditional formatting whereas over here I want it to be applied using VBA,

    Using these two lines I was applying color nos
    Please Login or Register  to view this content.
    However the normal functions used were not recording the color nos acquired due to Conditional Formatting, now with your coding as well as the other code I can get the colors but do not how to pass it to these above lines..

    As this is happening in a loop and each cell has a different format is that a challenge?

  50. #50
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    Are you wanting to collect the data of the formatting conditions as text?
    Or are you trying to set the formatting conditions in a range?

    Message #48 assumes the latter.
    If you are trying to set format conditions, you would need something like:

    Please Login or Register  to view this content.
    You would need to modify .Range & whateverRow.

  51. #51
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Can we Get/Apply Information of the Conditional Formatting used in any cell using VBA?

    NO Steve,

    I just need to get the Color Nos which are in the Sheet Report derived via Conditional FOrmatting and apply the same to the Sheet Replica..

    Whats happening is all the codes you are providing are giving me the color codes but I am unable to pass them to the Replica Sheet when it is created..

    Please Login or Register  to view this content.
    These lines are used to record the Font.Color & Interior.Color Nos from the Parent Sheet "REPORT" and also display them in a Single Column A Row-wise one below the other and the below lines..

    Please Login or Register  to view this content.
    are used to give the Font Color and the Interior Color and this works fine when theres no conditional formatting applied in the cells, however in case of Conditional Formatting APplied cells the color codes changes and are different for each cell based on the value of the contents in the column..

    So, I need a solution which acquires the color code nos and which can also be passed in the last two lines above to replace the question marks ? ? ? ? ? so that they apply the Font.Color & Interior.Color Nos from the Parent Sheet "REPORT" irrespective of the cells containing conditional formatting or not..

    As I am not good in VBA I am unable to do so the passing part..
    Hope this clarifies my lacunae and requirement..

    Answering your queries?
    Are you wanting to collect the data of the formatting conditions as text?
    Or are you trying to set the formatting conditions in a range?
    I need to mainly just apply the format colors and not the condition, I dont want the REPLICA sheet to contain any conditional formatting,
    Yes but if you can provide the information as to what Conditional Formatting is being used and show it in the formula that will be good but no so important.

    Analogy: Like these lines of code provide me the formula in the main sheet to be displayed as text
    Please Login or Register  to view this content.
    These lines are applying the formula in the REplica SHeet but later on it gets converted to Value..

    Please Login or Register  to view this content.
    Something similar for showing conditional formatting will do but I really dont need to apply it..

    Thanks in advance..
    Last edited by e4excel; 06-26-2012 at 04:06 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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