Conversion using VBA - Possible?

smods

Board Regular
Joined
Feb 18, 2008
Messages
79
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Is is possible for me to:

Have a cell set as a number
Enter a number
Have that number multiplied by 500
Convert to a currency cell ??

User enters "12" and then "£6,000" is displayed

Cheers

Chris
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
    Application.EnableEvents = False
    With Target
        .NumberFormat = "$#,##0.00"
        .Value = .Value * 500
    End With
    Application.EnableEvents = True
End If
End Sub

This is restricted to values typed in column A.
 
Upvote 0
Thank you VoG.

Is it possible for me to do this on a cell by cell basis as opposed to columns?

Regards

Chris
 
Upvote 0
Sure: change the range in red to suit

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2:F30")) Is Nothing Then
    Application.EnableEvents = False
    With Target
        .NumberFormat = "$#,##0.00"
        .Value = .Value * 500
    End With
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
You my friend are a genius! Thanks

A couple more questions if you don't mind..

How would I change the range for cells that are not together, If I wanted this to happen on cells C5, D10 & E12 for example?

Also my SUM function doesn't seem to be working at the bottom now to add all this up, is it something to do with the code?

Regards

Chris
 
Upvote 0
You can use e.g.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C5, D10, E12")) Is Nothing Then
    Application.EnableEvents = False
    With Target
        .NumberFormat = "$#,##0.00"
        .Value = .Value * 500
    End With
    Application.EnableEvents = True
End If
End Sub

The code won't prevent formulas from working - the only thing that it (and any other macro) will do is make Undo unavailable.
 
Upvote 0
Thank you.

My SUM is definately not working though and it is set to Automatic calculation in the options. I can't understand why it's not working :confused:
 
Upvote 0

Forum statistics

Threads
1,202,987
Messages
6,052,936
Members
444,616
Latest member
novit19089

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