PC Review


Reply
Thread Tools Rate Thread

check for last day of month

 
 
=?Utf-8?B?cHN3YW5pZQ==?=
Guest
Posts: n/a
 
      24th Sep 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UEpGcnk=?=
Guest
Posts: n/a
 
      24th Sep 2007
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.

"pswanie" wrote:

> 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
>

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      24th Sep 2007
On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
> 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


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

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      24th Sep 2007
One way
Sub lastday()
If Day(Date) = Day(DateSerial(Year(Date), _
Month(Date), 1) - 1) Then Range("a1").ClearContents
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"pswanie" <(E-Mail Removed)> wrote in message
news:42F42AEE-0036-4A05-AB49-(E-Mail Removed)...
>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
>


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      24th Sep 2007
Why is the simplest approach usually the best?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"JW" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
>> 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

>
> 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
>


 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
On Sep 24, 6:06 pm, "Don Guillett" <dguille...@austin.rr.com> wrote:
> Why is the simplest approach usually the best?
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> dguille...@austin.rr.com"JW" <JWRIGH...@triad.rr.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
> >> 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

>
> > 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


Unfortunately, from my experiences, it usually isn't. Just thought
that it would be the most efficient method in this case. Agree?

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
On Sep 24, 6:06 pm, "Don Guillett" <dguille...@austin.rr.com> wrote:
> Why is the simplest approach usually the best?
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> dguille...@austin.rr.com"JW" <JWRIGH...@triad.rr.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
> >> 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

>
> > 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


Unfortunately, from my experiences, it usually isn't. Just thought
that it would be the most efficient method in this case. Agree?

 
Reply With Quote
 
=?Utf-8?B?cHN3YW5pZQ==?=
Guest
Posts: n/a
 
      25th Sep 2007
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



"Don Guillett" wrote:

> Why is the simplest approach usually the best?
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "JW" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
> >> 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

> >
> > 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
> >

>
>

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
On Sep 25, 1:36 am, pswanie <pswa...@discussions.microsoft.com> wrote:
> 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
>
> "Don Guillett" wrote:
> > Why is the simplest approach usually the best?

>
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > dguille...@austin.rr.com
> > "JW" <JWRIGH...@triad.rr.com> wrote in message
> >news:(E-Mail Removed)...
> > > On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
> > >> 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

>
> > > 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


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

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
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

JW wrote:
> On Sep 25, 1:36 am, pswanie <pswa...@discussions.microsoft.com> wrote:
> > 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
> >
> > "Don Guillett" wrote:
> > > Why is the simplest approach usually the best?

> >
> > > --
> > > Don Guillett
> > > Microsoft MVP Excel
> > > SalesAid Software
> > > dguille...@austin.rr.com
> > > "JW" <JWRIGH...@triad.rr.com> wrote in message
> > >news:(E-Mail Removed)...
> > > > On Sep 24, 4:58 pm, pswanie <pswa...@discussions.microsoft.com> wrote:
> > > >> 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

> >
> > > > 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

>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Date, Include dates from rest of month and all of next month MSchmidty2 Microsoft Excel Programming 4 28th Jul 2009 05:08 PM
check if is last day of month then, else pswanie Microsoft Excel Programming 9 17th Mar 2008 01:16 AM
Check month jimmy Microsoft Excel Programming 10 4th Mar 2007 08:48 PM
printing Little Current month and Little Next month on Banner when it should little PRIOR month and little Next month. jake_allen10@hotmail.com Microsoft Outlook 0 3rd Nov 2006 07:30 PM
check day as well as month kaplonk Microsoft Excel Misc 3 11th Aug 2004 01:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 AM.