1
votes

In the following Excel spreadsheet, I need to make the following calculations:

Input      Color Selected        Output  
-------    --------------       --------
  40            red               40x18
  40            blue              40x12
  40            green             40x16
  40            yellow            40x13
  39            red               39x18
  28            blue              28x12
  33            green             33x16
  25            yellow            25x13

My question is, how can I assign values to the colors being selected using Java?

2
By spreadsheet do you mean an Excel spreadsheet or do you have some sort of Java implementation?willcodejavaforfood
Did you mean Visual Basic for Applications? Why did you tag the question as Java?George Stocker
In your example, how was the value 18 selected for red, or 12 for blue? Are these just random numbers?e.James
blue is always timsed by 12 and red is always times by 18. the colours were just an example. This is the first time ive used a forum and so sorry i have selected java.Lost

2 Answers

2
votes

It sounds like you want to be doing something like this... "Countif cell color is red". That is, you mean to apply different multipliers based on the format of a cell. See also "Color Functions In Excel".

But to be honest, the best thing to do is to create a new column that contains the semantics of the information you are trying to represent using formatting and use THAT for your conditional expression instead. Make a column that contains the information contained in the "color" formatting and use that.

1
votes

You could have a separate table with colors and numbers:

   |    F    |   G   |
---|---------|-------|--
 1 | red     |   18  |
 2 | blue    |   12  |
 3 | green   |   16  |
 . | ...     |   ..  |

And then use the table in your calculation:

   |   A   |     B     |                 C                 |
---|-------|-----------|-----------------------------------|--
 1 |   40  | red       |  =A1*VLOOKUP(B1,$F$1:$G$100,2,0)  |
 2 |   40  | blue      |  =A2*VLOOKUP(B2,$F$1:$G$100,2,0)  |
 . |   ..  | ...       |                ...                |