Hello,
I have an excel where I will select a Currency dropdown (USD,EUR,GBP,SGD). On selecting any one of the currencies, I need to change the currency symbol in multiple cells where the amount is entered.
My Drop down column & Amount column looks like this;
CELL LABEL CURRENCY
B5 Currency SGD
B23 Item amount (net!) 45.00
B29 Item amount (net!) 10.00
Thanks,
Vivek
3
Contributors
17
Replies
2 Weeks
Discussion Span
3 Months Ago
Last Updated
18
Views
Related Article:Combo Box Change Event
is a Visual Basic 4 / 5 / 6 discussion thread by Zick Technology that has 3 replies and was last updated 4 months ago.
Use the ActiveX ComboBox. It has a change event that you can handle. Also the changes that it makes to the linked cell also triggers the WorkSheet_Change event. The Forms drop down does not do this.
Are you just wanting to display the currency symbol depending on the currency chosen from your dropdown in Cell 'B5'? Could you show the layout, as it would be in Excel, the way you want it displayed?
If you only want the symbols to change you could alway just place the below formula in an adjacent cell and format to hide the divide between them. =IF($B$5="USD","$",IF($B$5="EUR","€",IF($B$5="GBP","£",IF($B$5="SGD","S$",""))))
Using this will change the symbol to what ever is selected in your dropdown in cell 'B5'.
I tend to use named ranges a lot when doing spreadsheet programming so I decided to attach a sample file for you to look at. I named the dropdown cell "SelectedCurrency" and the search text is "CurrencyTag" on the Data tab.
The code is:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim intersection As Range
Set intersection = Intersect([SelectedCurrency], Target)
If intersection Is Nothing Then Exit Sub
If intersection = [SelectedCurrency] Then
With ActiveSheet.Range("b:b")
Dim current As Range
Dim first As String
Set current = .Find([CurrencyTag].Value, LookIn:=xlValues)
If (Not (current Is Nothing)) Then
first = current.Address
Do
current.Offset(0, 1).NumberFormat = "[$" & [SelectedCurrency].Value & "] #,##0.00"
Set current = .FindNext(current)
Loop While (Not (current Is Nothing)) And (first <> current.Address)
End If 'Not current Is Nothing
End With 'ActiveSheet.Range("b:b")
End If 'Intersect([SelectedCurrency], Target) = [SelectedCurrency]
End Sub 'Worksheet_Change
Are you wanting the symbol in the same cell as the dollar values or in a cell next to it?
Could we see where in the code, and at what point, or when you would expect to see the symbol associated to the cell? Maybe a visual layout of what you have or a sample of what you currently have. Are you using a dropdown listbox object or a cell validation rule? If it is a validation in a cell on the sheet are you using a range referenced list or a typed list, in your dropdown validation?
Select Case [SelectedCurrency].Value
Case "USD"
current.Offset(0, 1).NumberFormat = "$ #,##0.00"
Case "EUR"
current.Offset(0, 1).NumberFormat = "€ #,##0.00"
etc.
End Select
Thank you for the upload of your file "vivek.vivek", it makes things a bit more clear as to what your trying to get.
If you are still looking for alternative methods...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = [SelectedCurrency] Then
Dim current As Range
Dim FirstAddress As String
Dim cFound As Range
With ActiveSheet.Range("b:b")
Set current = .Find(What:=[CurrencyTag], LookIn:=xlValues)
If current Is Nothing Then Exit Sub
FirstAddress = current.Address
Do
Set cFound = [Currencies].Find([SelectedCurrency], LookIn:=xlValues)
If cFound Is Nothing Then Exit Do
current.Offset(0, 1).NumberFormat = [CurrencyFormat].Cells(cFound.Row)
Set current = .Find(What:=[CurrencyTag], After:=current, LookIn:=xlValues)
Loop While Not current Is Nothing And current.Address <> FirstAddress
End With
End If
End Sub
You will have to change the layout of your "Data" sheet, and redefine "Currencies" as the entire column. As well as define the column which holds the formats which you want applied as "CurrencyFormat".
This code should allow you to Add, Delete or Modify your currencies list as well as the associated formats, with out having to redo or include new select Case currencies in your code. (See the attached / revised version of your example for reference.)
In the Revised Workbook Only Colunms 'B' ("Currencies") and 'C' ("CurrencyFormat") are important to the code the rest are purely informational. (I tend to get a little carried away...)
i run into some other problem now...I have some other dropdown in the same sheet to add or delete rows. So if i change the drop down , it is getting stuck and couldnot perform the action.
Does your second dropdown move or effect the currency selection dropdown at all?
What type of error do you get and what is actually happening when the other dropdown is used?
You may wish to try this slight code change:
From: If Target = [SelectedCurrency] Then
To: If Target.Address = [SelectedCurrency].Address Then
Not sure how much this will help... but until I know what is going on during the other drop down... But this should allow a line insert or a 'Target' object other than a single cell evaluation, (IE. Range or Cell).