Calculate cell value based on another cells format

mordrid

Board Regular
Joined
Jul 22, 2005
Messages
244
Hi, thanks for the help earlier the response worked, however, I misunderstood the ask of me and am struggling with the following issue

In cell A1 I have the value of the dollar exchange rate I want to use
In cell A2 I have the value of Euro exchange rate I want to use

In Col C I have a mix of Euro and Dollar values (cells are formatted as Accountancy dollar or Euro accordingly)

In Col D I would like to auto calculate the Pound value of the corresponding value in C but to do that I need to multiply the C value by the right exchange rate.

So something along the lines IF C2 is formatted as dollars then D2 would = C2*A1 but if C2 is formatted in Euros then D2 would = C2*A2

Any help or pointers gratefully accepted
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You can use the following formula in cell D2 and copy it down to the rest of the cells in column D:

VBA Code:
=IF(LEFT(C2,1)="$",C2*A1,C2*A2)
 
Upvote 0
You can use the following formula in cell D2 and copy it down to the rest of the cells in column D:

VBA Code:
=IF(LEFT(C2,1)="$",C2*A1,C2*A2)
Thanks, however when it looks for first character to be $ it returns false and therefore multiplies by the wrong exchange rate
 
Upvote 0
Thanks, however when it looks for first character to be $ it returns false and therefore multiplies by the wrong exchange rate
Ah yes, sorry the left function wont work here. Does this one work?

VBA Code:
=IF(CELL("format",C2)="$0.00",C2*A1,C2*A2)
 
Upvote 0
Think you will need to resort to a UDF to determine the format. Here's a simple UDF that returns a number greater than 0 if cell A1 is formatted as USD, 0 otherwise.
VBA Code:
Function ConvertIt(R As Range)
ConvertIt = InStr(1, R.Text, "$")
End Function
An example:
Book1
AB
1$ 100.362
2100.29 €0
Sheet1
Cell Formulas
RangeFormula
B1:B2B1=ConvertIt(A1)

With the UDF installed you could then use this worksheet formula:

=IF(ConvertIt(A1)> 0,C2*A1,C2*A2)
 
Upvote 0
As far as I know, there is no-way to determine if a cell is formatted as Dollars, or Euros with a formula
 
Upvote 0
As far as I know, there is no-way to determine if a cell is formatted as Dollars, or Euros with a formula
True for a native worksheet formula. See Post #6 for a simple UDF solution.
 
Upvote 0
What about?

VBA Code:
=IFERROR(IF(LEFT(TEXT(C2,"$#,##0.00"),1)="$",C2*A1,C2*A2),C2)
 
Upvote 0
Think you will need to resort to a UDF to determine the format. Here's a simple UDF that returns a number greater than 0 if cell A1 is formatted as USD, 0 otherwise.
VBA Code:
Function ConvertIt(R As Range)
ConvertIt = InStr(1, R.Text, "$")
End Function
An example:
Book1
AB
1$ 100.362
2100.29 €0
Sheet1
Cell Formulas
RangeFormula
B1:B2B1=ConvertIt(A1)

With the UDF installed you could then use this worksheet formula:

=IF(ConvertIt(A1)> 0,C2*A1,C2*A2)
Thanks, however, I am not sure how to set this UDF up
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top