#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default Calculate with code

I have this code


Private Sub Worksheet_Calculate(ByVal Target As Range)
Const WS_RANGE As String = "b47" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If UCase(.Value) = "#" Then
.Value = (7.15 * b47)
.NumberFormat = "#"
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

I am wanting to type a number for example 160 in b47 and it multiply by 7.15
and return the answer in B47.

Thanks
Chey
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Calculate with code

First, you can't just change those events and expect them to work.

I think you want something like:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "b47" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then
.Value = 7.15 * .Value
.NumberFormat = "#.##" '<-- I changed this
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub



Chey wrote:

I have this code

Private Sub Worksheet_Calculate(ByVal Target As Range)
Const WS_RANGE As String = "b47" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If UCase(.Value) = "#" Then
.Value = (7.15 * b47)
.NumberFormat = "#"
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

I am wanting to type a number for example 160 in b47 and it multiply by 7.15
and return the answer in B47.

Thanks
Chey


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Calculate with code

Try this. Of course, in the sheet module.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$B$47" Then Exit Sub

Application.EnableEvents = False
Target = Target * 10
Application.EnableEvents = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Chey" wrote in message
...
I have this code


Private Sub Worksheet_Calculate(ByVal Target As Range)
Const WS_RANGE As String = "b47" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If UCase(.Value) = "#" Then
.Value = (7.15 * b47)
.NumberFormat = "#"
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

I am wanting to type a number for example 160 in b47 and it multiply by
7.15
and return the answer in B47.

Thanks
Chey


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Code Question - Calculate eBay Fees Automatically shadrach Excel Worksheet Functions 5 September 21st 07 06:11 PM
UDF To Calculate Work hours between two dates Problem with code jlclyde Excel Discussion (Misc queries) 4 August 13th 07 06:47 PM
adding a code to calculate how much time is lost vwghia21 Excel Discussion (Misc queries) 3 September 6th 06 08:54 AM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"