Ask Experts Questions for FREE Help !
Ask
    rsdjimbie's Avatar
    rsdjimbie Posts: 96, Reputation: 3
    Junior Member
     
    #1

    Dec 7, 2009, 11:14 PM
    VBA code
    Once the month ends, cell "A1" must tick over to zero, where "A1" is used by me as a counter to show how much has been deliverd to date for the month.
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Dec 8, 2009, 01:22 PM

    Basically, you need to detect when the month rolls over.

    1. Unless the program is running all of the time (is it?), this can be tough to do. I'd suggest that whenever the program (Excel) terminates, you write a VBA routine that writes the current date and time to a disk file. If you open the program again, another VBA startup routine should look for the file. If it exists, the program can read the file and determine if the month has rolled over. If it has, it sets the appropriate cell to zero.

    2. While the program is running, you need to start an event that will trigger periodically. Excel has an "OnTime" function that you can use to do that. This is described in this article.

    Pearson Software Consulting

    The article also shows you how to use Windows Timers, if you wish to do that. For your application, you'll probably be best served using the OnTime function. I'd probably set it up to run once an hour, if I were you.

    In your subroutine -- the one that's invoked by the OnTime event, you'll have to determine the current month and compare it with the last month that you saved. You can do this as follows:

    Dim CurrentMonth as integer
    Dim NewMonth as integer

    Private Sub DetermineMonth
    NewMonth = Month(Now)
    If NewMonth <> CurrentMonth then
    Cells(Range("A1")) = 0 ' use this
    Cells(1,1) = 0 ' or this
    ' or any other way of assigning a value to a cell.
    CurrentMonth = NewMonth ' be sure and assign the CurrentMonth to the current month.
    End If
    End Sub
    rsdjimbie's Avatar
    rsdjimbie Posts: 96, Reputation: 3
    Junior Member
     
    #3

    Dec 11, 2009, 09:23 AM

    Thank you,
    Did get around the problem using a hiden (Month) formula.
    ie: NOW() - (Month)<>0 = set value to 0.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

VBA function for Date [ 1 Answers ]

Ok, here's my problem. I am trying to concatenate a Chart Title with a date in the MMM-YY format. I have to create a Chart in excel each month. If I create the chart in December, it would be for November's data. I can't figure out how to concatenate "Clinical Utilization: " &...

Revision date of Ca. Civil code 1945 making the new code 1945.5 [ 2 Answers ]

Hello. I need to know when civil code 1945 was revised into 1945.5. I cannot find it anywhere on line. Does anyone know? Thank you!

How I can convert Native Code to VB 6.0 Code [ 1 Answers ]

I have a decompiled VB 6.0 Project but source code in Native code but How I can convert Native Code to VB 6.0 Code ? Please solve this hot issue...

1989 honda civic. (code 4)crank angle sensor.(code 8) tdc position sensor [ 0 Answers ]

The car idles randomly after warm up.I check the ecu for codes and it gives 4 crank angle sensor and 8 tdc position sensor. I did a search and one of the ad posted by a guy in Canada says that he had to get part from different vehicles until he got all of them to work properly. Will I be able to...


View more questions Search