+ Reply to Thread
Results 1 to 35 of 35

Multiple Data Bars

  1. #1
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Multiple Data Bars

    Hi, I am somthing of a novice (with a little experience ) using Excel 2010

    I am trying to use 2 data bars in one cell to represent the following:-

    If the value is for example 32, then there would be a green data bar filling 32% of the cell, and if the value was -32, there would be a red data bar filling 32% of the cell. I can achieve this individually, but if I have 2 data bar rules, Excel only looks at the first one.

    I found what I thought was the answer on the following website ( https://blogs.office.com/2006/02/24/...red-data-bars/ )

    Is says to use the following VBA ... selection.FormatConditions(1).formula = “=if(c3>59, true, false)”


    However, when I tried it, it dosen't work, Is there a possibility to achieve my objective in this way or any other, is there something simple I could be doing wrong that stops the above vba from working?

    Thanks for any help
    Paul

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Multiple Data Bars

    sherman51,
    Your title do show the issue you are running into, please update it
    Attach a sample of your data to prepare the macro
    - Battle without fear gives no glory - Just try

  3. #3
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    These settings work for me. Do you want VBA code?

    FormattingRule.jpg


    NegValues.jpg
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  4. #4
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Thanks for your reply Kevin, however i need to have 2 rules in order to get what i want ..... pic attached
    Thanks

    I am looking for this to be possible in one cell dependent on the value ..


    Pauldata bars.JPG

  5. #5
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    thanks for your reply, i have replied to another post, i hope that makes it clearer what i am looking for.
    Thanks
    Paul

  6. #6
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    Paul - that is exactly what it does.
    Put 50 in the cell and it goes green, put -50 in the cell and it goes red
    Did you make the minimum -100?

  7. #7
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Thanks Kevin, but the problem is that this method works in reverse for the negative values, ie if the cell value is for example -2, then this will give you a long red bar, and if the cell value is say -90, then there is a very small bar ..

    Thanks
    Paul

  8. #8
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    That is not a problem

    Let's say the cell to be formatted (say E1) gets its value from A1 and that A1 contains values between -100 and +100

    The formula in cell E1 :
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This turns -32 into -68 etc and should give you what you want

  9. #9
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    thanks Kevin, that looks to be a neat fix .....

    However, let me give you an exact example, lets say the cell that needs the format is T4 and there is already a calc in there which is =IFERROR(V3-L3,0) and lets say that the result would be -36.45, i would like to see a red bar representing a 36.45 segment of the cell (no need to be exact) and the actual number, like in my image .. is that still possible?

    Thanks for your continued efforts, really appreciated
    Paul

  10. #10
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    Under the formatting rule, uncheck the box indicated in picture

    FormattingRuleShowBarOnly.jpg

  11. #11
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    I already have that un checked,

    I think the only way to do this is to have 2 seperate rules ( which is what I have in my picture ) and to somehow get excel to use "either or" as that vba code promised to, it seems that the only way it will display negative and positive bars is from the center .. but thanks very much for your help, much appreciated ..
    Paul

  12. #12
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    VBA does indeed seem the only way
    Try the attached workbook.
    Amend value in A1 and see if what you get in E1 is what you want

    this is the formula in cell E1 - turns negatives to positives
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    The code is on the sheet's module
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    IF this is what you want I will modify the code so that it is available in a more general way (ie using variables, and loops), instead of only one cell at a time
    Attached Files Attached Files
    Last edited by Kevin#; 04-23-2016 at 01:37 PM.

  13. #13
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Thanks Kevin, yes that does actually work, thank you for your trouble ....

    Just as a matter of interest, can you say why the vba that I found would not work ? it is supposed to allow either the positive or the negative data bar rule to work depending on positive or negative value ....


    selection.FormatConditions(1).formula = “=if(c3>59, true, false)”

    Cheers
    Paul

  14. #14
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    Hi Paul

    Here is a more general solution for you and now uses selection.FormatConditions(1).formula = “=if(c3>59, true, false)” (I was distracted down the change "negative" to "positive" and forgot to go back to the beginning!)

    In the test worksheet, the range is set to E1 to E50 and so you will need to amend that to suit yourself.
    It runs automatically when anything changes in column E. But you could run it anytime

    The cell bar is coloured red (if negative) or green (if positive), and the bar will totally fill the cell if value = 100 or -100

    If you need any help adapting it to your workbook, give us a shout.
    Otherwise if this gives you everything you need, please mark the thread as solved (under thread tools at top of thread)



    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    That works great Kevin, thank you very much ...

    With regards to applying it to my workbook, i could do with a bit of advice, i will want to apply it to 26 columns but alternate cells ie, L4, L6, L8 up to L68, then N4, N6. N8 up to N68 ... and so on ..

    also, would it be possible to have solid fill rather than the graduated ends ... no big deal if not

    Thanks again
    Paul

    One other issue I just discovered Kevin, the cells to be formatted will get their value from a calc that comes from a live feed and may fluctuate meaning that at first the value may be positive but in time it may change to negative. I have found that when i tried this the first value would work and the correct data bar would appear, but if it was positive and the incoming data ment that it changed to negative, tha calc changed to show the correct value but the data bar dissapeared leaving a clear cell with just the number.

    sorry to be a pain but we are so close ...

    I found a way to make the bars solid btw, so thats ok

    Cheers
    Paul
    Last edited by sherman51; 04-25-2016 at 02:31 PM. Reason: additions

  16. #16
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    "would it be possible to have solid fill rather than the graduated ends"

    Add this line in both the "red" and "green" zone
    Please Login or Register  to view this content.

    1. Are the 26 columns adjacent to each other?
    - makes it easier if they are

    2. Are all the odd rows blank (spacers between all the green & red) ?
    - if blank then we can format them as well as it will not show
    Last edited by Kevin#; 04-25-2016 at 02:28 PM.

  17. #17
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    The cols are not ajacent .... could it be done with named sets ?

    unfortunately the odd rows are not blank, they have calcs in them too, but i don't want them formated ...

    did you see my edit to the last post

    Cheers
    Paul

  18. #18
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    I had not noticed the edit to your last post.
    I am not concerned about the formatting disappearing - it appears to be an Excel quirk. I've noticed it myself too - it's temporary until the macro is re-run. Just call the macro at the end of any procedure where the values are being updated. Notation is
    Please Login or Register  to view this content.
    Are all values updated automatically, rather than direct input?

    I will sleep on the " non-adjacent cells that require formatting " puzzle.
    - hopefully we can come up with a "rule" that can be applied (I would not like to list all those cells individually)
    - the rows are easy - all the even numbers
    - I am guessing that columns will need listing separately or is there a pattern?
    - there are 26 columns being formatted, how many other columns are likely to be embedded amongst our 26?
    - Will there be other conditional formatting in the other columns?

  19. #19
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    "I will want to apply it to 26 columns but alternate cells ie, L4, L6, L8 up to L68, then N4, N6. N8 up to N68 ... and so on .."

    which means every other row and every other column starting at L4, in which case this will work:
    (see attached workbook, sheet2)

    Please Login or Register  to view this content.
    Are we there?
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Thanks again Kevin ..

    I am not sure where to put the "call Macroname"

    RE the cells to be formatted, i am quite prepared to put in the legwork to make named ranges of all the cells required if named ranges can be used, I realised last night that when i said 26 cols it is in fact 52 cols, its every other (even) cell decending starting with 4 up to and including 68 in each case ... so L4 L6 .... L68, but the cols are not evenly spaced, they start with L & N, then t & V, then AB & AD etc ...

    The sheet is being updated every 10 seconds (with vba) and is linked to another sheet, thats how the incoming data arrives ..

    Cheers
    Paul
    Last edited by sherman51; 04-26-2016 at 02:24 AM.

  21. #21
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    Did post 19 not give you exactly that?

    Where is the VBA sitting that updates the worksbook - is it in this workbook or the other one?

    I am offline now for about 3 hours - car MOT

  22. #22
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Post 19 formats every other column, I would need the following pattern, starting with L4 - miss 1 col - N4, then miss 5 cols - T4 miss 1 col - V4, then miss 5 cols - AB4 - miss 1 col - AD4 .. and so on, ...

    Every other row is correct .. so 4, 6, 8, 10 up to 68 ..

    The calc update every 10secs vba is in another file that I open first ..

    Cheers
    Paul
    Last edited by sherman51; 04-26-2016 at 07:37 AM. Reason: changed a fig

  23. #23
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    I offer you 2 choices:
    1 Put a marker in each column that should be formatted in this way ( eg an "X" in row 100)
    - this is easy and flexible - would allow you add extra columns and it would still work without modification
    - VBA would loop through looking for the marker
    OR
    2 Hard wire the columns
    - means inputting each column number/letter

    Which do you prefer?
    (my choice would be No1 )
    Let me know and I will tailor the code.

  24. #24
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    I will take your advice Kevin, No 1 sounds fine,

    just as a matter of interest .. would there be any issues ie speed , if I am using possibly say 35 sheets at the same time running with this code ?

    Cheers
    Paul

  25. #25
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    It will be marginally slower than reading directly from hard code, but not a choker.
    I do not think I would hook it to a "change event" routine. Either run it automatically at end of other procedures or as once-off if you amend anything manually.
    I would insert the macro at sheet level to avoid having to refer to the worksheet by name. Everything happens within the same sheet.

    See sheet3 in attached workbook. Looks ok to me.

    Code included to dump a message to screen in case rows are later added/deleted above row 100) - the value in cell I100 also acts as a reminder explaining the "X"

    Please Login or Register  to view this content.
    PS
    Just a thought - it may be helpful to remove conditional formatting from a column (if you put an X in the wrong place etc or change your mind) - so I will send you something to do that later.
    Attached Files Attached Files
    Last edited by Kevin#; 04-26-2016 at 10:13 AM.

  26. #26
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Hi Kevin, thanks again for your continued work ..

    I am however still having a problem with the change from pos to neg values ...

    What i have done to simulate the live action is put a simple calc in say O4 of =IFERROR(M1-N1,0) I then change the numbers in M1 & N1 and hit f9 to calculate (Calculate needs to be set to manual), if the result is positive all is fine, but if the result is negative then there is no formatting, just a clear cell with the answer ...

    I also added a couple of X's in other cols and they did not produce a bar when i entered a number ..

    Sorry to be a pain, maybe I am doing something wrong

    Cheers
    Paul

  27. #27
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    All that is missing is a trigger to fire the macro.
    The formatting is correct if you run the macro manually after putting X in the column or after putting in a negative value

    If you add this macro at sheet level then it will run the macro with every change you make. Make sure amend "J:CZ" to include all your columns
    TwoColourDataBar is the name of the macro

    Please Login or Register  to view this content.

  28. #28
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Thanks Kevin, i have inserted the trigger code after the code in the sheet, i am novice so not sure if that was correct, i also deleted the test data from teh code, again I don't know if that was the right thing to do but it got a result. I now can change from pos to neg and back ..

    so now when i change a number you see each cell highlighted and then it stops at the last cell, but if that happend it would be continually dumping me at the end of the sheet. is it possible that when the figs update that the sheet stays static? because i am usually studying the sheet and it would be unworkable to be put at the end of the sheet every 10 secs ..

    Also, i still get no joy when i enter in a fresh col that I have marked with an x at row 100 .. Sorted!! I just realised it needs to be a capital ...

    I now have to leave for the evening so will be in touch tomorrow
    Thanks
    Paul
    Last edited by sherman51; 04-26-2016 at 12:58 PM. Reason: Sorted!! I just realised it needs to be a capital ...

  29. #29
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    Hi Paul

    Test is for upper case "X"

    so either input in Upper Case
    OR
    - amend the code to include lower case "x"
    Please Login or Register  to view this content.
    OR
    - amend the left side so that it does not matter what you input
    Please Login or Register  to view this content.

    The mod you asked for:
    This leaves cursor where it is and by wrapping "ScreenUpdating" False/True around things stops the annoying screen flicker.
    Please Login or Register  to view this content.

  30. #30
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Hi Kevin, that worked fine thanks, but I have been checking throught the sheet typing numbers into the cell inbetween the formatted cells and find that randomly some of them format, a few examples ... L7, L19, L35, O33, O45 ....

    Also, when I copy the code to a new workbook i get an error when i try to type anwhere on the sheet ...

    "Marker row has moved from row 100 Amend vba / move it back!"

    thanks
    Paul

  31. #31
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    1. Enter "GreenRed" in cell "I100" in each new worksheet or remove ths bit of code
    (it is only there to help you later if you inset/delete rows - the conditional formatting is dependant on there being an "X" in row 100 - if you insert/delete rows then the "X" will end up in a different row)
    Please Login or Register  to view this content.
    2. The random formatting is the legacy of previous testing left behind. Unfortunately it is invisible until you put a value in the cell!

    Here are 3 macros to clear the debris. Suggest you attach a shortcut to each one for ease


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    RunningMacrosWithShortcuts.jpg

  32. #32
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    it appears that the macros only clear the unwanted formatting after the cells are populated, is that correct?

    I amy have up to 40 sheets running and getting updated every 10 secs, I just wonered how that would work out...

    I obviously don't understand how vba works, but if i copied (re-typed?) your vba into a new sheet with a new name would that be like a fresh start without the legacy ?

    Cheers
    Paul
    got your message thanks ..

  33. #33
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    The formatting should clear instantly - whether cells populated or not.
    (EDIT - The formatting should clear instantly when the macro is next run)

    Any formatting legacy is in the worksheet not in the vba.
    So if you copy (or template) one worksheet to create another, the new sheet takes the old sheet's formatting at the point of copying

    This clears conditional formatting from all cells in the active worksheet
    Please Login or Register  to view this content.
    If you run that it clears everything, and then you can run the other macro which will then only format the cells you want.
    (NB if you have conditionally formatted any other cells those will need re-formatting separately)

    EDIT
    and to answer your question
    "but if i copied (re-typed?) your vba into a new sheet with a new name would that be like a fresh start without the legacy ?"
    Yes, provided you have created a fresh sheet
    Last edited by Kevin#; 04-27-2016 at 06:34 AM.

  34. #34
    Registered User
    Join Date
    08-26-2015
    Location
    Staffordshire UK
    MS-Off Ver
    2007
    Posts
    98

    Re: Multiple Data Bars

    Thank you so much Kevin for you help and giving your time, I have also learned new stuff with your help.

    All the best
    Paul

  35. #35
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Multiple Data Bars

    You are welcome. I hope all your bars are green!

+ 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. Conditional formatting data bars into quartiles/multiple stock charts
    By kcranick in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-06-2014, 03:05 PM
  2. Replies: 1
    Last Post: 07-23-2014, 11:53 PM
  3. Conditional Formatting using multiple colored data bars
    By macquarl in forum Excel General
    Replies: 2
    Last Post: 02-17-2014, 11:38 AM
  4. Excel 2007 : multiple error bars
    By itsmekelli3 in forum Excel General
    Replies: 1
    Last Post: 10-09-2011, 01:39 AM
  5. How to have multiple bars in the same column?
    By okmate in forum Excel General
    Replies: 2
    Last Post: 05-03-2010, 07:58 AM
  6. multiple floating bars
    By rusticus in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-06-2008, 02:54 PM
  7. [SOLVED] How can I change a graph with 2 bars,2 lines to 3 bars, 1 line?
    By IOWAJulie in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 10-19-2005, 07:05 PM

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