If your values are currency formatted then using left will not work - it pulls back the first digit, not the currency prefix.
This code may help you get started. It converts £ to R (South African Rand).
Sub CurrencyConverter()
Dim cl As Range, rng As Range
Set rng = Range("CampusCurrRng")
For Each cl In rng
If cl.NumberFormatLocal = "£#,##0;[Red]-£#,##0" And cl.Value <> "" Then
cl = cl * 50
cl.NumberFormat = "[$R-1C09] #,##0;[Red][$R-1C09] -#,##0"
End If
Next
End Sub
Notes:
To check for £ you need to specify the currency format. This is tricky. For example, I am in the UK and if I have £100 in cell A1:
Range("A1").NumberFormat ~~~> $#,##0_);[Red]($#,##0)
Range("A1").NumberFormatLocal ~~~> £#,##0;[Red]-£#,##0
You need to use NumberFormatLocal to pick up £. Put another way, this code will produce a negative result in the loop:
If cl.NumberFormat = "£#,##0;[Red]-£#,##0"...
The next bit is easier. You need to specify the output currency format. For South African Rand I have:
cl.NumberFormat = "[$R-1C09] #,##0;[Red][$R-1C09] -#,##0"
To get the one you need I would do the following:
- Type a random value in a random cell e.g. 100 in cell A1
- Select the cell and press
F1 (brings up the Format Cells dialog)
- Select
Currency in the left hand navigation
- Select your desired currency format in the
Symbol drop down menu
- Click
OK
- Now press
F1 again
- In the left hand navigation select
Custom
- The right hand navigation will now show the correct format
This all seems a little like hard work. I am interested to see if any simpler approaches surface!
cell- should it bec? - Alex PR? South African Rand? - Alex P