Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Popup for cell change

I'm using Excel 2000. I have a spreadsheet where a user enters numbers for
debits and credits. I'd like to have a popup appear when the user enters a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.

Also, is there a way to erase or undo the previous entry?

I'm thinking the worksheet_change event is needed here, but what I've tried
doesn't seem to work:

Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub

Thanks for any and all help.



--
Craig
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Popup for cell change

Hi Craig,

Assuming that the Debit and Credit entries are in different columns, why not
use Data Validation, with conditions of = 0 for debits and <= 0 for
credits.
If zero is not a valid option, simplify the condition to 0 and < 0.

Also, is there a way to erase or undo the previous entry?


If the undo buttion does not satisfy your needs, please add some
explanation.

---
Regards,
Norman



"Craig" wrote in message
...
I'm using Excel 2000. I have a spreadsheet where a user enters numbers
for
debits and credits. I'd like to have a popup appear when the user enters
a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.

Also, is there a way to erase or undo the previous entry?

I'm thinking the worksheet_change event is needed here, but what I've
tried
doesn't seem to work:

Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub

Thanks for any and all help.



--
Craig



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Popup for cell change

I think Data Validation is what you want. Example:

1) Select the cells that you want to allow only positive whole numbers
(Debits).
2) Select Data from the Worksheet Menu Bar
3) Select Validation
4) In the Allow window, select "Whole number"
5) In the Data window select "Greater than" or "Greater than or equal to"
6) In the Minimum window enter "0"
7) If you want to display a message when the user selects a cell in the
range then select the Input Message tab and enter an appropriate message
8) Select the Error Alert tab and select the desired Error Style, Title and
error message
9) Repeat for the Credit range except change selections as appropriate

Regards,
Greg

"Craig" wrote:

I'm using Excel 2000. I have a spreadsheet where a user enters numbers for
debits and credits. I'd like to have a popup appear when the user enters a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.

Also, is there a way to erase or undo the previous entry?

I'm thinking the worksheet_change event is needed here, but what I've tried
doesn't seem to work:

Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub

Thanks for any and all help.



--
Craig

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Popup for cell change

Well, good suggestions. However, what I need to do is something Data
Validation can't handle.

I have a scenario where the user can enter numbers ANYWHERE on the
spreadsheet (not 1 column for debits, 1 for credits). The client wants an
input page - so the user might enter the letters "DR" in cell A1, then 75,000
in cell B1, etc...something like this:

A1 B1
DR 75,000
DR 80,000
CR -75,000
CR -36,000
CR -56,000
CR -89,000
..
..
etc, etc...

So, you can see that if the user types a "DR", then the number had better be
positive, not negative. I realize that this may seem like an innefficient
way to do this. But it's set up the way the client wanted, etc. These
numbers to other spreadsheets, as well. So it's important that they're
entered correctly.

So, I'm back to where I started. I think I need to do this with VBA. Any
suggestions?

Thanks again.


--
Craig


"Greg Wilson" wrote:

I think Data Validation is what you want. Example:

1) Select the cells that you want to allow only positive whole numbers
(Debits).
2) Select Data from the Worksheet Menu Bar
3) Select Validation
4) In the Allow window, select "Whole number"
5) In the Data window select "Greater than" or "Greater than or equal to"
6) In the Minimum window enter "0"
7) If you want to display a message when the user selects a cell in the
range then select the Input Message tab and enter an appropriate message
8) Select the Error Alert tab and select the desired Error Style, Title and
error message
9) Repeat for the Credit range except change selections as appropriate

Regards,
Greg

"Craig" wrote:

I'm using Excel 2000. I have a spreadsheet where a user enters numbers for
debits and credits. I'd like to have a popup appear when the user enters a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.

Also, is there a way to erase or undo the previous entry?

I'm thinking the worksheet_change event is needed here, but what I've tried
doesn't seem to work:

Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub

Thanks for any and all help.



--
Craig

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Popup for cell change

Maybe something like this then:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

If Target.Count = 1 And Target.Column 1 _
And IsNumeric(Target.Value) Then
If UCase(Target.Offset(0, -1).Value) = "DR" Then
If Target.Value < 0 Then
MsgBox "Debit must be positive"
Target.Value = ""
End If
ElseIf UCase(Target.Offset(0, -1).Value) = "CR" Then
If Target.Value 0 Then
MsgBox "Credit must be negative"
Target.Value = ""
End If
End If
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

This is worksheet event code. Right click the sheet tab, select View
Code and paste the code in there.

Hope this helps
Rowan

Craig wrote:
I'm using Excel 2000. I have a spreadsheet where a user enters numbers for
debits and credits. I'd like to have a popup appear when the user enters a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.

Also, is there a way to erase or undo the previous entry?

I'm thinking the worksheet_change event is needed here, but what I've tried
doesn't seem to work:

Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub

Thanks for any and all help.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Popup for cell change

Rowan:

That looks like exactly what I'm looking for, except one problem: When I
cut and paste it into my worksheet, it doesn't work.

The entire Worksheet_Change event doesn't even trigger. In other words,
nothing happens at all.

Even when I set a step break to occur, it bypasses it. Don't know what to
do. Is there something that I need to do or "turn off" first (ie, rules,
etc.)??

Thanks.
--
Craig


"Rowan" wrote:

Maybe something like this then:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

If Target.Count = 1 And Target.Column 1 _
And IsNumeric(Target.Value) Then
If UCase(Target.Offset(0, -1).Value) = "DR" Then
If Target.Value < 0 Then
MsgBox "Debit must be positive"
Target.Value = ""
End If
ElseIf UCase(Target.Offset(0, -1).Value) = "CR" Then
If Target.Value 0 Then
MsgBox "Credit must be negative"
Target.Value = ""
End If
End If
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

This is worksheet event code. Right click the sheet tab, select View
Code and paste the code in there.

Hope this helps
Rowan

Craig wrote:
I'm using Excel 2000. I have a spreadsheet where a user enters numbers for
debits and credits. I'd like to have a popup appear when the user enters a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.

Also, is there a way to erase or undo the previous entry?

I'm thinking the worksheet_change event is needed here, but what I've tried
doesn't seem to work:

Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub

Thanks for any and all help.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Popup for cell change

Hi Craig

What have you done to test it? Bear in mind that this will not work on
data that is already on the sheet but rather any new value entered.

If you are sure you have pasted the code into the sheets code module,
enter DR in cell A1 and then -5000 in cell B1. If that doesn't work then
type
application.enableevents = true
in the VBE immediate window and hit enter.
Then try entering another -ve value in B1.

Regards
Rowan

Craig wrote:
Rowan:

That looks like exactly what I'm looking for, except one problem: When I
cut and paste it into my worksheet, it doesn't work.

The entire Worksheet_Change event doesn't even trigger. In other words,
nothing happens at all.

Even when I set a step break to occur, it bypasses it. Don't know what to
do. Is there something that I need to do or "turn off" first (ie, rules,
etc.)??

Thanks.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Popup for cell change

That seemed to do the trick (application.enableevents=true).

Thanks for the assistance.
--
Craig


"Rowan" wrote:

Hi Craig

What have you done to test it? Bear in mind that this will not work on
data that is already on the sheet but rather any new value entered.

If you are sure you have pasted the code into the sheets code module,
enter DR in cell A1 and then -5000 in cell B1. If that doesn't work then
type
application.enableevents = true
in the VBE immediate window and hit enter.
Then try entering another -ve value in B1.

Regards
Rowan

Craig wrote:
Rowan:

That looks like exactly what I'm looking for, except one problem: When I
cut and paste it into my worksheet, it doesn't work.

The entire Worksheet_Change event doesn't even trigger. In other words,
nothing happens at all.

Even when I set a step break to occur, it bypasses it. Don't know what to
do. Is there something that I need to do or "turn off" first (ie, rules,
etc.)??

Thanks.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Popup for cell change

You're welcome

Craig wrote:
That seemed to do the trick (application.enableevents=true).

Thanks for the assistance.

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
Showing known cell reference in a popup Colin Hayes Excel Worksheet Functions 4 May 31st 10 04:19 PM
Automating change via popup to a column of numbers Colin Hayes Excel Worksheet Functions 0 May 28th 09 02:59 PM
User entry in cell creates popup Bryan Excel Discussion (Misc queries) 3 January 5th 09 08:34 PM
If values are'nt entered in cell a popup window comes up?? pano Excel Worksheet Functions 5 February 14th 07 02:30 PM
How do I create a popup window based on a cell value? bumper338 Excel Discussion (Misc queries) 2 November 28th 06 03:05 PM


All times are GMT +1. The time now is 03:29 PM.

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"