variable formats

rodney_malodney

Board Regular
Joined
Jul 19, 2005
Messages
116
hi, i've got a program that gives particular currency formats in required cells. they are found from a userform, with four options.

Code:
Private Sub CommandButton1_Click()
'


Dim format As Currency
Dim text1 As String
Dim text2 As String

If OptionButton1 = True Then

text1 = "Total Sales Price £"
text2 = "List Price £"
format = "$#,##0.00"
Else
If OptionButton2 = True Then

text1 = "Total Sales Price €"
text2 = "List Price €"
format = "[$€-2] #,##0.00"
Else
If OptionButton3 = True Then

text1 = "Total Sales Price DKK"
text2 = "List Price DKK"
format = "[$DKK] #,##0.00"
Else
If OptionButton4 = True Then

text1 = "Total Sales Price $"
text2 = "List Price $"
format = "[$$-409]#,##0.00"

Application.EnableEvents = False

Sheets("Summary Sheet").Select
ActiveSheet.Unprotect
Range("c13:c44").Select
Selection.NumberFormat = format
Range("C47").Select
Selection.NumberFormat = format
Range("C49").Select
Selection.NumberFormat = format
ActiveSheet.Protect
  '
  Sheets("sales sheet (1)").Select
  ActiveSheet.Unprotect
  Range("H154").Select
  Selection.NumberFormat = format
  Range("H8").Select
  ActiveCell = text1
  Range("G8").Select
  ActiveCell = text2
  Range("G17:H153").Select
  Selection.NumberFormat = format
  ActiveSheet.Protect

  '
  UserForm2.Hide
  '
  Sheets("Cover Sheet").Select
  '
 Application.ScreenUpdating = True
'
End If
End If
End If
End If
Application.EnableEvents = True
End Sub

basically my problem lies in that i can't select a currency variable to declare as.

if only there was a "dim ~~~ as format"

i hope i haven't confused anyone... :confused:
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Rodney

Why do you want to declare format as Currency (or Format)?

It should be declared as a String.

By the way you should avoid variable names like format as they might
clash with VBA properties like Format.
 
Upvote 0
Also note that you can condense your code by eliminating the Select statements:

Code:
With Sheets("sales sheet (1)")
    .Unprotect
        .Range("H154, G17:H153").NumberFormat = Format
        .Range("H8") = text1
        .Range("G8") = text2
    .Protect
End With

And I'm definitely with Norie on avoiding using reserved names.

Hope that helps,

Smitty
 
Upvote 0

Forum statistics

Threads
1,217,380
Messages
6,136,227
Members
450,000
Latest member
jgp19

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