Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default IF DATE Statement help please

Hi I would like to use the following type of statement (I think
unfortunately my brain is in "Excel not VBA mode"):

IF

Then Else

Or Else

I wish to use the criteria that If date (date = 1st of the month) AND
Day = Sun, =Range("A1")
If Day = Sat AND DATE = 1 = Range("A2")
Else = Range("A3")

Thanks for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default IF DATE Statement help please


I'm clear on what it is that you're tryign to achieve.


dim source as range
IF Day(Date)= 1 AND format$(date,"DDD") = "Sun" THEN
set source = Range("A1")
ELSEIF Day(Date)= 1 AND format$(date,"DDD") ="Sat" THEN
set source = Range("A2")
ELSE
set source = Range("A3")
END IF


some might suggest that instead of
format$(date,"DDD")
you could use the WEEKDAY() function. Makes no difference to the logic
either way

"Simon" wrote:

Hi I would like to use the following type of statement (I think
unfortunately my brain is in "Excel not VBA mode"):

IF

Then Else

Or Else

I wish to use the criteria that If date (date = 1st of the month) AND
Day = Sun, =Range("A1")
If Day = Sat AND DATE = 1 = Range("A2")
Else = Range("A3")

Thanks for your help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default IF DATE Statement help please

Just as a follow up, this is what Patrick's code would look like using the
WeekDay function...

Dim Source As Range
If Day(Date) = 1 And Weekday(Date) = vbSunday Then
Set Source = Range("A1")
ElseIf Day(Date) = 1 And Weekday(Date) = vbSaturday Then
Set Source = Range("A2")
Else
Set Source = Range("A3")
End If

where I have used the built-in VB constants vbSunday (which is equal to 1)
and vbSaturday (which is equal to 7) for their self-documenting feature.

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in message
...

I'm clear on what it is that you're tryign to achieve.


dim source as range
IF Day(Date)= 1 AND format$(date,"DDD") = "Sun" THEN
set source = Range("A1")
ELSEIF Day(Date)= 1 AND format$(date,"DDD") ="Sat" THEN
set source = Range("A2")
ELSE
set source = Range("A3")
END IF


some might suggest that instead of
format$(date,"DDD")
you could use the WEEKDAY() function. Makes no difference to the logic
either way

"Simon" wrote:

Hi I would like to use the following type of statement (I think
unfortunately my brain is in "Excel not VBA mode"):

IF

Then Else

Or Else

I wish to use the criteria that If date (date = 1st of the month) AND
Day = Sun, =Range("A1")
If Day = Sat AND DATE = 1 = Range("A2")
Else = Range("A3")

Thanks for your help


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default IF DATE Statement help please

And another followup...

Sometimes using lots of if/then/else's can confuse me.

Dim Source As Range

set source = nothing 'a flag

select case day(date)
case is = 1
select case weekday(date)
case is = vbsunday
set source = range("A1")
case is = vbsaturday
set source = range("A2")
case else
set source = range("a3")
end select
case is = ....
'do more stuff???
end select

if source is nothing then
'not set
else
'do something with Source
end if



Rick Rothstein wrote:

Just as a follow up, this is what Patrick's code would look like using the
WeekDay function...

Dim Source As Range
If Day(Date) = 1 And Weekday(Date) = vbSunday Then
Set Source = Range("A1")
ElseIf Day(Date) = 1 And Weekday(Date) = vbSaturday Then
Set Source = Range("A2")
Else
Set Source = Range("A3")
End If

where I have used the built-in VB constants vbSunday (which is equal to 1)
and vbSaturday (which is equal to 7) for their self-documenting feature.

--
Rick (MVP - Excel)

"Patrick Molloy" wrote in message
...

I'm clear on what it is that you're tryign to achieve.


dim source as range
IF Day(Date)= 1 AND format$(date,"DDD") = "Sun" THEN
set source = Range("A1")
ELSEIF Day(Date)= 1 AND format$(date,"DDD") ="Sat" THEN
set source = Range("A2")
ELSE
set source = Range("A3")
END IF


some might suggest that instead of
format$(date,"DDD")
you could use the WEEKDAY() function. Makes no difference to the logic
either way

"Simon" wrote:

Hi I would like to use the following type of statement (I think
unfortunately my brain is in "Excel not VBA mode"):

IF

Then Else

Or Else

I wish to use the criteria that If date (date = 1st of the month) AND
Day = Sun, =Range("A1")
If Day = Sat AND DATE = 1 = Range("A2")
Else = Range("A3")

Thanks for your help


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default IF DATE Statement help please

On Oct 7, 12:26*pm, Patrick Molloy
wrote:
I'm clear on what it is that you're tryign to achieve.

dim source as range
IF Day(Date)= 1 AND format$(date,"DDD") = "Sun" *THEN
set source = Range("A1")
ELSEIF Day(Date)= 1 AND format$(date,"DDD") ="Sat" THEN
set source = Range("A2")
ELSE
set source = Range("A3")
END IF

some might suggest that instead of
format$(date,"DDD")
you could use the WEEKDAY() function. Makes no difference to the logic
either way



"Simon" wrote:
Hi I would like to use the following type of statement (I think
unfortunately my brain is in "Excel not VBA mode"):


IF


Then Else


Or Else


I wish to use the criteria that If date (date = 1st of the month) AND
Day = Sun, =Range("A1")
If Day = Sat AND DATE = 1 = Range("A2")
Else = Range("A3")


Thanks for your help- Hide quoted text -


- Show quoted text -


As for Excel/VBA options are always abound, thanks for your suggestion
Patrick
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Statement for a date jlo Excel Worksheet Functions 4 June 17th 09 06:02 PM
if statement with date JJ Excel Worksheet Functions 2 April 9th 09 08:03 PM
How can I use a date in an IF/AND statement? gsmith Excel Discussion (Misc queries) 2 July 13th 05 12:27 AM
If statement with date Tanya Excel Discussion (Misc queries) 4 May 20th 05 01:42 AM
Date in an IF statement LyndieBee Excel Worksheet Functions 2 March 8th 05 04:11 PM


All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"