+ Reply to Thread
Results 1 to 20 of 20

to change shape colour by conditional formating/ VBA

  1. #1
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    to change shape colour by conditional formating/ VBA

    I have shape of a pump named "group 558" inserted in sheet 1. Cell B4 linked with another cell in sheet 2 and gets value either 1 or 0 if the pump is running or in stop position.

    The requirement is colour of shape should change to green when cell B4 gets value 1 and changes to red when gets 0 (zero).

    Colour changes happens as required when I enter the value 1 or 0 in cell B4 manually, but it fails when it takes the values via the cell link. How this problem can be resolved? thanks.

    the code given is as follows
    Please Login or Register  to view this content.
    Last edited by Fotis1991; 11-02-2013 at 02:50 PM. Reason: Pls use code tags around your codes

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,607

    Re: to change shape colour by conditional formating/ VBA

    To attach a Workbook
    (please do not post pictures of worksheets)
    • Click Advanced (next to quick post),
    • Scroll down until you see "Manage Attachments",
    • Click that then select "add files" (top right corner).
    • Click "Select Files" find your file, click "open" click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Click "Done" at bottom right to close the Attachment Manager.
    • Click "Submit Reply"
    Ben Van Johnson

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: to change shape colour by conditional formating/ VBA

    Hi there,

    As written, the colour will change only if Cell "B4" happens to be the active cell - try the following code instead:

    Please Login or Register  to view this content.
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  4. #4
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Thanks, it works good.

    If I want to link the active cell B4 to a cell in another work sheet, for eg. Sheet2, what change to be made in the code? Please help.

    thanks

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: to change shape colour by conditional formating/ VBA

    Hi again,

    Move (or copy as appropriate) the code to the VBA CodeModule of sheet "Sheet2" and change the following line:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    (where "Sheet1" is the name of the worksheet which contains the Shape)

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  6. #6
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi for immediate response.
    Little confused, my shape is in sheet 1, active cell is B4 in sheet 1 and linked to cell A4 in sheet 2. Should I retain the code in sheet 1 as before and copy the code to sheet 2 with replaced line. Could you please explain? Better give code separately for both the sheets, if you don't mind. file attached.
    thanks
    Attached Files Attached Files

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: to change shape colour by conditional formating/ VBA

    Hi again,

    Place the following code in the VBA CodeModule of the worksheet "Sheet2"

    Please Login or Register  to view this content.
    You don't need to have any code in the VBA CodeModule of the worksheet "Sheet1"

    Please let me know if this works for you.

    Regards,

    Greg M

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: to change shape colour by conditional formating/ VBA

    Here is another alternative. This is untested since there isn't a sample worksheet to test it on.
    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  9. #9
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi
    It works perfectly, thanks a lot.

    If I have more pumps(shapes) to be displayed on the same sheet 1 and the reference cells are in sheet 2(eg A4, A5, A6 etc), how this can be achieved? Now I have the shape name as "Group 558". I have similar shapes named "Picture 1", "Picture 2" etc. Then how the code will be changing. Should I write separate code for each shape?
    thanks

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: to change shape colour by conditional formating/ VBA

    If you are going to be adding more reference cells and shapes, I would change from the way the code is currently written, to a code using a select case syntax.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: to change shape colour by conditional formating/ VBA

    If you use a transparent image then you can do away with code and simply use CF
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  12. #12
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi,
    I have another problem. When I put 1 or 0 in the active cell or linked cell, it works. But as these numbers 1 or 0 are generated by system or by the excel formula, it doesn't work. The file is attached. The cell F8 gets 1 or 0 OR cell G8 have "run" or "stop". How this issue can be solved?
    Attached Files Attached Files

  13. #13
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: to change shape colour by conditional formating/ VBA

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi

    Thanks for the reply. Unfortunately it doesn't work. Could you please look into it and find a solution, file modified with new code attached

    thanks
    Attached Files Attached Files

  15. #15
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: to change shape colour by conditional formating/ VBA

    Because you're using a combobox and a formula the worksheet_change event is not being triggered. try
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi

    I doesn'work. That means the code will not work with combobox in the worksheet? Any other way to resolve this issue?

    thanks

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: to change shape colour by conditional formating/ VBA

    The code in post 15 worked fine for me on your sample document.

  18. #18
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi,
    Please find the attached file. When I enter "RUN" manually in cell G8, the cell F8 get the value 1 and it works. But when I select the equipment thru the combo box and the cell G8 get "RUN" or "STOP" string and cell F8 gets the required value 1 or 0, it doesn't work. Could you please look into it.

    thanks
    Attached Files Attached Files

  19. #19
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: to change shape colour by conditional formating/ VBA

    The your most recently attached workbook did not have the code from post #15. Please see attached file.

    Note- the formatting is different from your original sample, though it doesn't seem to be causing any problems.

    pump%20run%20indication%206(1).xlsm

  20. #20
    Registered User
    Join Date
    03-03-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: to change shape colour by conditional formating/ VBA

    Hi

    It works perfectly. thanks

+ 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] Excel - conditional formating on graphs. Change colour on a value
    By Peter Shore in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 07-09-2013, 06:00 AM
  2. Replies: 3
    Last Post: 05-22-2012, 03:26 PM
  3. Conditional Formating-change colour
    By vandanavai in forum Excel General
    Replies: 1
    Last Post: 01-26-2007, 05:24 AM
  4. Conditional Formating-change the cell colour to green
    By stevekirk in forum Excel General
    Replies: 4
    Last Post: 10-20-2006, 02:52 AM
  5. Conditional formating-change colour when D30 is equal
    By smith.james0 in forum Excel General
    Replies: 2
    Last Post: 07-26-2005, 01: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