Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

check for last day of month

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pswanie - 24 Sep 2007 21:58 GMT
i need a mocro to check if its the last day of the month and if so del
contents in cell a1

for example

chek if day = 31 then del range a1. if only 30 days in month then
chek if day = 30 then del range a1. if only 28 days in month then
chek if day = 28 then del range a1. if non of above then nothing

it can use the system date to chek what month is the current month
PJFry - 24 Sep 2007 22:40 GMT
Try this:

Sub EndMonth()

If Range("D1") = Evaluate("=EOMONTH(Now(),0)") Then
Range("A1").Delete
End If

End Sub

You need to replace the D1 with the location of your date.  Set this to run
with the workbook opens.  

One note: The EOMonth function requires the Analysis ToolPack.  If you get
an error, check under Tools => Add-Ins to make sure it is installed.  

> i need a mocro to check if its the last day of the month and if so del
> contents in cell a1
[quoted text clipped - 6 lines]
>
> it can use the system date to chek what month is the current month
JW - 24 Sep 2007 22:42 GMT
> i need a mocro to check if its the last day of the month and if so del
> contents in cell a1
[quoted text clipped - 6 lines]
>
> it can use the system date to chek what month is the current month

Or, you can simply check if the Date + 1 equals the first of the next
month.
If Day(Date + 1) = 1 Then Range("A1").ClearContents
Don Guillett - 24 Sep 2007 23:06 GMT
Why is the simplest approach usually the best?

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

>> i need a mocro to check if its the last day of the month and if so del
>> contents in cell a1
[quoted text clipped - 10 lines]
> month.
> If Day(Date + 1) = 1 Then Range("A1").ClearContents
JW - 25 Sep 2007 00:16 GMT
> Why is the simplest approach usually the best?
>
[quoted text clipped - 17 lines]
> > month.
> > If Day(Date + 1) = 1 Then Range("A1").ClearContents

Unfortunately, from my experiences, it usually isn't.  Just thought
that it would be the most efficient method in this case.  Agree?
JW - 25 Sep 2007 00:16 GMT
> Why is the simplest approach usually the best?
>
[quoted text clipped - 17 lines]
> > month.
> > If Day(Date + 1) = 1 Then Range("A1").ClearContents

Unfortunately, from my experiences, it usually isn't.  Just thought
that it would be the most efficient method in this case.  Agree?
pswanie - 25 Sep 2007 06:36 GMT
Nope sory guys.....   nether of those two options worked.

i placed the date in range N31 and the range that needs to be cleared will
be c24

and i need this macro to run with in a nother one

> Why is the simplest approach usually the best?
>
[quoted text clipped - 12 lines]
> > month.
> > If Day(Date + 1) = 1 Then Range("A1").ClearContents
JW - 25 Sep 2007 12:11 GMT
> Nope sory guys.....   nether of those two options worked.
>
[quoted text clipped - 24 lines]
> > > month.
> > > If Day(Date + 1) = 1 Then Range("A1").ClearContents

Should work no problem.  How about this.  I separated the sub out.
Now you can call it whenever and wherever you want.
Sub dateCheck(ByVal dRange As Range, ByVal clearRange As Range)
   If Day(dRange + 1) = 1 Then clearRange.ClearContents
End Sub

Call it like this wherever needed and simply pass whatever arguments
you want to:
Sub testThis()
   dateCheck Range("N31"), Range("C24")
End Sub
JW - 25 Sep 2007 13:06 GMT
Might want to throw a check in there too to make sure that dRange is
infact a date.
Sub dateCheck(ByVal dRange As Range, ByVal clearRange As Range)
   If Not IsDate(dRange.Value) Then
       MsgBox dRange.Address & " is not in date format", , "Error"
   Else
       If Day(dRange + 1) = 1 Then clearRange.ClearContents
   End If
End Sub

> > Nope sory guys.....   nether of those two options worked.
> >
[quoted text clipped - 36 lines]
>     dateCheck Range("N31"), Range("C24")
> End Sub
Don Guillett - 24 Sep 2007 22:46 GMT
One way
Sub lastday()
If Day(Date) = Day(DateSerial(Year(Date), _
Month(Date), 1) - 1) Then Range("a1").ClearContents
End Sub

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

>i need a mocro to check if its the last day of the month and if so del
> contents in cell a1
[quoted text clipped - 6 lines]
>
> it can use the system date to chek what month is the current month
Ron Rosenfeld - 26 Sep 2007 19:54 GMT
>i need a mocro to check if its the last day of the month and if so del
>contents in cell a1
[quoted text clipped - 6 lines]
>
>it can use the system date to chek what month is the current month

Sub ClearAtEOM()
 If Day(Date + 1) < Day(Date) Then [a1].ClearContents
End Sub

--ron
Ron Rosenfeld - 26 Sep 2007 20:20 GMT
>>i need a mocro to check if its the last day of the month and if so del
>>contents in cell a1
[quoted text clipped - 12 lines]
>
>--ron

I see JW has posted an even simpler method:

If Day(Date + 1) = 1 Then [a1].ClearContents

--ron
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.