Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Worksheet_Calculate Question

I am very new to VBA, so I appreciate any help on this one. I am using a
worksheet_calculate event to trigger a msg box if a user enters a value that
exceeds a limit on a sheet.

Basically, a user enters a value on an input sheet. then, some calcs are
performed and a title cell either stays the same, or changes to over. on
another sheet, i have a formula to count all the instances of the word over,
and then use that value to trigger some other msgs.

With the worksheet_calculate, the msg box appears as i want it to, but the
user has already entered the value that causes the overage and hit enter or
tab and has moved to the next cell. How can i make the worksheet_calculate
move the cursor back to the previous cell and highlight the incorrect entry
so that it has to be corrected?

Here is the code I have so far:

Private Sub Worksheet_Calculate()

Dim Over As Range
Dim msb As Integer

Application.EnableEvents = False

For Each Over In Range("W37")
If Over.Value 0 Then
msb = MsgBox("You have entered a value which exceeds the maximum
limit. Please try again.")
ElseIf Over.Value = 0 Then Exit Sub
End If

Application.EnableEvents = True

Next

End Sub

Any suggestions would be appreciated.


  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Worksheet_Calculate Question

could you use Application.Undo to remove the data that was input?

"Volsfan" wrote:

I am very new to VBA, so I appreciate any help on this one. I am using a
worksheet_calculate event to trigger a msg box if a user enters a value that
exceeds a limit on a sheet.

Basically, a user enters a value on an input sheet. then, some calcs are
performed and a title cell either stays the same, or changes to over. on
another sheet, i have a formula to count all the instances of the word over,
and then use that value to trigger some other msgs.

With the worksheet_calculate, the msg box appears as i want it to, but the
user has already entered the value that causes the overage and hit enter or
tab and has moved to the next cell. How can i make the worksheet_calculate
move the cursor back to the previous cell and highlight the incorrect entry
so that it has to be corrected?

Here is the code I have so far:

Private Sub Worksheet_Calculate()

Dim Over As Range
Dim msb As Integer

Application.EnableEvents = False

For Each Over In Range("W37")
If Over.Value 0 Then
msb = MsgBox("You have entered a value which exceeds the maximum
limit. Please try again.")
ElseIf Over.Value = 0 Then Exit Sub
End If

Application.EnableEvents = True

Next

End Sub

Any suggestions would be appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Worksheet_Calculate Question

Use the worksheet_selectionchange event to trap any selection and save that
in a module scope variable, and then when you get the error, just pick up
that variable and activate that cell.

Option Explicit

Private oCell As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set oCell = Target
End Sub

Private Sub Worksheet_Calculate()
Dim Over As Range
Dim msb As Integer

Application.EnableEvents = False

For Each Over In Range("W37")
If Over.Value 0 Then
msb = MsgBox("You have entered a value which " & _
"exceeds the maximum limit. Please try again.")
oCell.Activate
ElseIf Over.Value = 0 Then Exit Sub
End If
Next

Application.EnableEvents = True

End Sub

--
HTH

Bob Phillips

"Volsfan" wrote in message
...
I am very new to VBA, so I appreciate any help on this one. I am using a
worksheet_calculate event to trigger a msg box if a user enters a value

that
exceeds a limit on a sheet.

Basically, a user enters a value on an input sheet. then, some calcs are
performed and a title cell either stays the same, or changes to over. on
another sheet, i have a formula to count all the instances of the word

over,
and then use that value to trigger some other msgs.

With the worksheet_calculate, the msg box appears as i want it to, but the
user has already entered the value that causes the overage and hit enter

or
tab and has moved to the next cell. How can i make the worksheet_calculate
move the cursor back to the previous cell and highlight the incorrect

entry
so that it has to be corrected?

Here is the code I have so far:

Private Sub Worksheet_Calculate()

Dim Over As Range
Dim msb As Integer

Application.EnableEvents = False

For Each Over In Range("W37")
If Over.Value 0 Then
msb = MsgBox("You have entered a value which exceeds the maximum
limit. Please try again.")
ElseIf Over.Value = 0 Then Exit Sub
End If

Application.EnableEvents = True

Next

End Sub

Any suggestions would be appreciated.




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
worksheet_calculate code Jase Excel Discussion (Misc queries) 1 October 29th 08 08:17 PM
worksheet_calculate enyaw Excel Discussion (Misc queries) 2 January 26th 07 01:16 PM
worksheet_calculate enyaw Excel Discussion (Misc queries) 0 January 26th 07 08:14 AM
Worksheet_calculate() Alex Excel Programming 1 August 30th 05 10:09 PM
worksheet_calculate **help** tommyboy Excel Programming 2 June 29th 04 08:33 AM


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

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

About Us

"It's about Microsoft Excel"