More answers.
This code uses Integer variables to store dates. However, Excel dates exceed the Integer value limits. You must use Long for dates.
The variables "CurrReceiptDate" and "PrevReceiptDate" refer to the day number in the month rather than an actual date and as such are integers, i.e. 21-Apr-2021 would be the integer 21. The actual date is derived from this number. There are a number of reasons for this but it is mainly to facilitate trying out different payment options and dates.
It is almost always better to refer directly to sheets and cells. Instead of doing this, this code Selects a sheet and cell, and then depends on ActiveCell to refer to it.
I picked this up from another site and thought it was the way to do it, the code has been updated and now uses a With-End With loop, see latest code.
How does the following line of code determine a date? It refers to column C, which does not contain a date. It contains the result of this function, so it seems this is circular logic.
Column "C" is meant to be the day number of the month and is used by the formula in column "B" to calculate the date in the form dd-mm=yyyy and the day in column "A" in the form dddd. See above for an explanation.
However, you have a point regarding circular logic as this is one of the errors I have been getting. I need the function to return the day number of the receipt for the current month, so how do I do that without creating a circular reference?
Why is the following code commented out?
This code is meant to deal with the month that has two receipts in it .i.e. if there are more than 28 days from the receipt date to the last day of the month. The month will vary from year to year. It will be implemented once the main code is working properly and may be ignored for now.
The crux of the matter, as I see it, is how to pass back the value obtained by the function. With the code segment
activated, running the code from the code window using F5 gives the correct result and running gives a #VALUE Error.
I am trying to get the code into the example worksheet already posted and am now getting some quite bizarre results!
The code line
is going to a totally unrelated function in a different module that I use to obtain the value of the corresponding cell in the previous sheet. Running the code again it stops at
and displays a Run-time error '1004' Unable to get the EoMonth property of the worksheet function class. It displays it for the next line of code as well. Closing the workbook and reopening it lets this code fragment run.
I am now totally confused and not sure what to do next so I am taking a break and will come back to it with, I hope, a fresh pair of eyes and a clear head.
I hope the answers to your questions help.
Thanking you once again for you interest
Tegglet
Bookmarks