Morning All,
I was wondering if you could help me tidy up/optimize some code.
I have created a combobox with a list of countries. Based on the country selected I want it to format a range of cells to the appropriate currency for that country. (Basically to save having to change a load of cells on multiple sheets every time I use this template to run a report.)
The problem I have is the code is quite bulky with a list of currencies and codes, I was wondering if there was a way to clean this up at all? I am planning to build on this code so I want to keep it as lean as I can.
Thanks in advance,
Thomas
Private Sub ConfigureFileButton_Click()
'Error handler to ensure a country is selected
If Me.CurrencySelector.Value = "" Then
MsgBox "Please select a country from the drop down list"
End If
Dim Y As String
If Me.CurrencySelector = "Switzerland" Then
Y = "[$CHF] #,##0.00"
If Me.CurrencySelector = "Ireland" Then
Y = "[$EUR] #,##0.00"
If Me.CurrencySelector = "United Kingdom" Then
Y = "[$GBP] #,##0.00"
'etc etc for the other countries listed below.
End If
'Change currency to selected value
Sheets("Analysis").Select
Range("D5:AA1000,AF5:AF1000,AH5:BR1000,BV5:BX1000,BZ5:BZ1000,CB5:CB1000,CD5:CH1000,CN5:CO1000,CQ5:CV1000").Select
Selection.NumberFormat = Y
Sheets("Analysis2").Select
Range("D5:P1000,S5:BT1000,BX5:BZ1000,CD6:CD1000,CF6:CF1000,CG5:CJ1000,CP5:CQ1000,CS5:CW1000").Select
Selection.NumberFormat = Y
Sheets("Analysis3").Select
Range("F3:AO1000").Select
Selection.NumberFormat = Y
Sheets("Analysis4").Select
Range("H3:S1000").Select
Selection.NumberFormat = Y
Sheets("Analysis 5").Select
Range("F3:AO1000").Select
Selection.NumberFormat = Y
Sheets("Analysis1").Activate
Range("A1").Activate
Unload OpeningForm
End Sub
Private Sub UserForm_Initialize()
'populate drop down with list of currencies
With Me.CurrencySelector
'Clear previous list to prevent duplicates
.Clear
'Add countries to drop down box
.AddItem "Armenia"
.AddItem "Austria"
.AddItem "Azerbaijan"
.AddItem "Belarus"
.AddItem "Belgium"
.AddItem "Bosnia & Herzegovnia"
.AddItem "Croatia"
.AddItem "Czech Republic"
.AddItem "Denmark"
.AddItem "Estonia"
.AddItem "France"
.AddItem "Germany"
.AddItem "Hungary"
.AddItem "Iceland"
.AddItem "Ireland"
.AddItem "Israel"
.AddItem "Latvia"
.AddItem "Lithuania"
.AddItem "Luxembourg"
.AddItem "Netherlands"
.AddItem "Norway"
.AddItem "Poland"
.AddItem "Portugal"
.AddItem "Russia"
.AddItem "Serbia"
.AddItem "Slovakia"
.AddItem "Spain"
.AddItem "Sweden"
.AddItem "Switzerland"
.AddItem "United Arab Emirates"
.AddItem "United Kingdom"
End With
End Sub
Display More