+ Reply to Thread
Results 1 to 5 of 5

If function based on color of the shape

  1. #1
    Registered User
    Join Date
    04-21-2013
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2007
    Posts
    5

    If function based on color of the shape

    Short description:

    I need to do little project on VBA and this is what I've come up: a car does laps based on number of laps user entered. But there is also a traffic light,
    and if the traffic light is green, it does a normal lap, but if it's red, it has to do the bigger one. Problem is that I have no clue how to read the color value from a shape.

    I will also add my file so you can take a look: Sheet2Problem.xlsm

    For example:
    if shape("light").color=green then
    do
    car_1.incrementleft speed + rnd()*10
    paus 0.04
    loop until car_1.left > line_5.left
    or something like that.
    Last edited by mjoll; 04-21-2013 at 12:50 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: If function based on color of the shape

    hi mjoll,

    red - RGB(255,0,0)
    green - RGB(0,255,0)

    to check if shape "tuli" color is red:
    Please Login or Register  to view this content.
    for green
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-21-2013
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: If function based on color of the shape

    Thank you!
    I've come up with yet another problem.

    My code is as follows:

    Please Login or Register  to view this content.
    There is similar code for color "red". What I want to achieve though is that the excel would check color of the light every time it crosses the finish line and
    acts accordingly. But with this code it recognises the color once in the beginning and loops until the end. I have tried to take "IFs" inside "Do" function, but
    somehow messed up. Any ideas? Btw, n is number of laps. Thanks! I also added a piece of code down below, I hope it's not too messy, it doesn't work
    but hopefully it describes my problem.

    Please Login or Register  to view this content.

    Moderators note: code tags added for you - this time
    Last edited by mjoll; 04-21-2013 at 05:00 PM.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: If function based on color of the shape

    Please use code tags when posting VBA code, it keeps it neat, and easier to read/copy
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: If function based on color of the shape

    please check attachment, run code "soida". The light turns to green or red in turn changing the car route, amend to your required logic
    Attached Files Attached Files

+ 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