Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Sub procedures


Hi,

I am a newbie to VBA.
Can any one help me in answering this question?

(Q4)
The following worksheet contains some dates in cells A2:A9.

Date New Display Leap Year
2/5/2004
28/09/2000
12/8/2001
23/07/1976
31/12/1836
15/03/2084
8/10/2800
22/02/1736

Write a sub procedure to perform the following operations:
(a) Display the dates in the column B in the form, for exampl
02/ May/2004,
(b) Indicate whether the year is a leap year in column C wit
Yes or No.

Conditions for a year to be a leap year:
A year is a leap year, if it is divisible by 4;
But, it is not a leap year, if it is divisible b
100;
However, it is a leap year, if it is divisibl
by 400


Thank You Very Much!
Lexie

--
lexie
-----------------------------------------------------------------------
lexiez's Profile: http://www.excelforum.com/member.php...fo&userid=1498
View this thread: http://www.excelforum.com/showthread.php?threadid=26603

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default VBA Sub procedures


Excel cannot work properly with dates before 1/1/1900.
VBA can.. so we can circumvent it with a few userdefined functions.

create a module in your workbook
copy following code...

Function DateReformat(s As String)
If IsDate(s) Then
DateReformat = Format(DateValue(s), "dd\/mm\/yyyy")
ElseIf s = vbNullString Then
DateReformat = Empty
Else
DateReformat = CVErr(xlErrValue)
End If
End Function

Function LeapYear(s As String)
If IsDate(s) Then
LeapYear = Day(DateSerial(Year(DateValue(s)), 2, 29)) = 29
ElseIf s = vbNullString Then
LeapYear = Empty
Else
LeapYear = CVErr(xlErrValue)
End If
End Function


Now in B2 type = DateReformat(A2)
Now in C2 type = LeapYear(A2)

and copy down..







keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


lexiez wrote:

Date New Display Leap Year
2/5/2004
28/09/2000
12/8/2001
23/07/1976
31/12/1836
15/03/2084
8/10/2800
22/02/1736



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default VBA Sub procedures

Hi, keepITcool,
Instead of: DateReformat = Format(DateValue(s), "dd\/mm\/yyyy")
perhaps : DateReformat = Format(DateValue(s), "dd\/mmm\/yyyy")
Jorge
"keepITcool" escreveu na mensagem
...

Excel cannot work properly with dates before 1/1/1900.
VBA can.. so we can circumvent it with a few userdefined functions.

create a module in your workbook
copy following code...

Function DateReformat(s As String)
If IsDate(s) Then
DateReformat = Format(DateValue(s), "dd\/mm\/yyyy")
ElseIf s = vbNullString Then
DateReformat = Empty
Else
DateReformat = CVErr(xlErrValue)
End If
End Function

Function LeapYear(s As String)
If IsDate(s) Then
LeapYear = Day(DateSerial(Year(DateValue(s)), 2, 29)) = 29
ElseIf s = vbNullString Then
LeapYear = Empty
Else
LeapYear = CVErr(xlErrValue)
End If
End Function


Now in B2 type = DateReformat(A2)
Now in C2 type = LeapYear(A2)

and copy down..







keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


lexiez wrote:

Date New Display Leap Year
2/5/2004
28/09/2000
12/8/2001
23/07/1976
31/12/1836
15/03/2084
8/10/2800
22/02/1736





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
Separating sub procedures JAW Excel Discussion (Misc queries) 4 January 28th 09 12:17 PM
VBA function Procedures.... Arif[_2_] Excel Worksheet Functions 1 June 3rd 08 01:54 PM
Sequential Sub Procedures Roger[_10_] Excel Programming 3 November 20th 03 04:32 PM
what's wrong with this sub procedures? active_x[_4_] Excel Programming 8 September 10th 03 05:25 AM
VBA -- procedures as arguments? Dave Ring Excel Programming 1 August 27th 03 02:27 AM


All times are GMT +1. The time now is 01:24 AM.

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

About Us

"It's about Microsoft Excel"