VBA: notify when number switches from positive to negative and vice versa (Excel)

Status
Not open for further replies.

zeno

Board Regular
Joined
Feb 16, 2012
Messages
71
Hello,
I have a column in Excel with both positive and negative numbers. I would like to receive through VBA a notification on screen every time in the list a number switches sign from one row to the other. The notification is different with a change from positive to negative than from negative to positive. It would also have to indicate at what row that change happens.
Thank you for your help.
 
This is working!
I may make a few smaller changes, but this is nice work!
Thanks again!

A small follow-up:
if I would like this message to be automatically triggered, how can that be done?
 
Last edited:
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
if I would like this message to be automatically triggered, how can that be done?
Automatics triggers happen based on some "event" happening. This is what triggers the code to run. So what event do you want to trigger this code to run?
 
Upvote 0
The event would be the change of sign. But maybe that would only happen if new data are coming in? For the moment I have an excel file with data, so the analysis can be done instantaneously with all data already available.
The trigger event would happen if new data inflow would generate new log lines. Maybe my follow-up question was meant for a later stage and is this too soon?
 
Upvote 0
It is possible that a Worksheet_Change event procedure will work for you. That is triggered anytime a value is manually changed on the spreadshseet.

Here is a write-up on all the event procedures: http://www.cpearson.com/excel/Events.aspx
 
Upvote 0
Thanks for the Worksheet_Change event procedure. I'm reading it now.

Is it possible to make different log depending on the type of change of sign? So if the change is from - sign to + sign, the log could indicate that the number turned positive. And the other way around.
 
Upvote 0
Is it possible to make different log depending on the type of change of sign? So if the change is from - sign to + sign, the log could indicate that the number turned positive. And the other way around.
Of course. Just include the myCurrentSign and/or myLastSign variables in the statement where the log is written out. Give it a shot!
 
Upvote 0
I have a question on the log:
When checking the log, I realize that it would identify as first switch of sign the first line with a number, i.e. from blank to a number (there are a few blank rows in the beginning). This is incorrect.
How can it identify only switches from numbers, not including blank cells?
 
Upvote 0
You can specify in the code where the data starts. Just update that line of code.
Code:
'   Designate which row to run on
    myStartRow = 2
 
Upvote 0
I actually have a variable starting point. So in that case identification of non-blank cells, not including row 1 with a title, would be the most direct approach.
If such a non-blank cell identifier does not exist, I may have to find out a work around.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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