PC Review


Reply
Thread Tools Rate Thread

Conditional Formatting Problem with currency.

 
 
Summerstone
Guest
Posts: n/a
 
      10th Jul 2007
Hi all,

I have a quotation tool where cell C13 can be "GBP", "USD" or "EUR", a
data validation where the user can choose the currency.

I'd like the figures in the spreadsheet to have their currency format
dependant on that cell.

Conditional formatting isn't an option, this only allows basic
formatting, not currency.

I've tried looking at a selection change event in VBA but with my
limited experience it going nowhere.

Any suggestions would be much appreciated!!

Many thanks,
Tony Summers

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      10th Jul 2007
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Offset(0, -1).Value
Case "GBP": .NumberFormat = "£#,##0.00;(£#,##0.00)"
Case "USD": .NumberFormat = "\$#,##0.00;(\$#,##0.00)"
Case "EUR": .NumberFormat = "#,##0.00?;(#,##0.00?)"
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Summerstone" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> I have a quotation tool where cell C13 can be "GBP", "USD" or "EUR", a
> data validation where the user can choose the currency.
>
> I'd like the figures in the spreadsheet to have their currency format
> dependant on that cell.
>
> Conditional formatting isn't an option, this only allows basic
> formatting, not currency.
>
> I've tried looking at a selection change event in VBA but with my
> limited experience it going nowhere.
>
> Any suggestions would be much appreciated!!
>
> Many thanks,
> Tony Summers
>



 
Reply With Quote
 
Summerstone
Guest
Posts: n/a
 
      10th Jul 2007
Hi Bob,

Many many thanks for your quick reply, much appreciated.

It's not your fault, but I'm struggling to make the code work. I
pasted it in as an event code but must be missing something simple.

A couple of queries:
The WS_RANGE... is that the area I wish to be formatted? (I notice
you've commented "change to suit").
Where is the user input of "GBP, USD" identified by the code?
I assume a "worksheet_change" event is simply that? A user "changes"
something?

Sorry to be slow, I'm very much at the start of my VBA journey!

Many thanks,
Tony





 
Reply With Quote
 
Summerstone
Guest
Posts: n/a
 
      10th Jul 2007
I've managed to throw together the following which seems to be working
fine.
I can now enter the currency in A1 and the formatting of the quotes
changes accordingly.

I'm still concious that this is a bit clunky, so am still keen to
understand Bob's code above, if anyone is willing to humour me.

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("A1") = "USD" Then
Range("G4:H33").Select
Selection.NumberFormat = "[$$-409]#,##0.00"
Range("G4").Select
Range("a1").Select
Else
If Range("A1") = "GBP" Then
Range("G4:H33").Select
Selection.NumberFormat = "£#,##0.00"
Range("A1").Select

Else
If Range("A1") = "EUR" Then
Range("G4:H22").Select
Selection.NumberFormat = "[$€-2] #,##0.00"
Range("A1").Select

End If
End If
End If

End Sub

Best regards,
Tony

 
Reply With Quote
 
Summerstone
Guest
Posts: n/a
 
      10th Jul 2007
I've managed to throw together the following which seems to be working
fine.
I can now enter the currency in A1 and the formatting of the quotes
changes accordingly.

I'm still concious that this is a bit clunky, so am still keen to
understand Bob's code above, if anyone is willing to humour me.

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("A1") = "USD" Then
Range("G4:H33").Select
Selection.NumberFormat = "[$$-409]#,##0.00"
Range("G4").Select
Range("a1").Select
Else
If Range("A1") = "GBP" Then
Range("G4:H33").Select
Selection.NumberFormat = "£#,##0.00"
Range("A1").Select

Else
If Range("A1") = "EUR" Then
Range("G4:H22").Select
Selection.NumberFormat = "[$€-2] #,##0.00"
Range("A1").Select

End If
End If
End If

End Sub

Best regards,
Tony

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      10th Jul 2007
My code adapted to your situation should be

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "G4:H33"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range("A1")) Is Nothing Then
With Target
Select Case .Value
Case "GBP": Me.Range(WS_RANGE).NumberFormat = "£#,##0.00"
Case "USD": Me.Range(WS_RANGE)..NumberFormat =
"[$$-409]#,##0.00"
Case "EUR": Me.Range(WS_RANGE)..NumberFormat = "[$?-2]
#,##0.00"

End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

WS_RANGE would normally point to the range being changed, but here I have
altered it to the range affected down the line, and test A1 for a change. If
A1 changes, I reformat the WS_RANGE range accordingly.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Summerstone" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I've managed to throw together the following which seems to be working
fine.
I can now enter the currency in A1 and the formatting of the quotes
changes accordingly.

I'm still concious that this is a bit clunky, so am still keen to
understand Bob's code above, if anyone is willing to humour me.

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("A1") = "USD" Then
Range("G4:H33").Select
Selection.NumberFormat = "[$$-409]#,##0.00"
Range("G4").Select
Range("a1").Select
Else
If Range("A1") = "GBP" Then
Range("G4:H33").Select
Selection.NumberFormat = "£#,##0.00"
Range("A1").Select

Else
If Range("A1") = "EUR" Then
Range("G4:H22").Select
Selection.NumberFormat = "[$?-2] #,##0.00"
Range("A1").Select

End If
End If
End If

End Sub

Best regards,
Tony


 
Reply With Quote
 
Summerstone
Guest
Posts: n/a
 
      11th Jul 2007
Works perfectly, really appreciate your help Bob.

As importantly, I understand the approach too!

Many thanks,
Tony

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Currency conditional formatting Yossy Microsoft Excel Programming 0 31st Oct 2008 02:16 AM
Conditional formatting - currency? emailus@knowles.net.au Microsoft Excel Programming 2 5th Jun 2008 03:50 PM
conditional formatting for currency =?Utf-8?B?VEM=?= Microsoft Excel Worksheet Functions 1 20th May 2006 01:55 PM
Conditional Currency Formatting wagonboytim Microsoft Excel Misc 1 16th Sep 2004 04:31 PM
Conditional Formatting for Currency Andy Edmunds Microsoft Excel Programming 1 18th Jul 2003 04:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 PM.