Hi,
Ive typed in the following code inVBA to run see which year is a leap year etc. The code is not working form me is this the right function am using??
![]()
Please Login or Register to view this content.
Hi,
Ive typed in the following code inVBA to run see which year is a leap year etc. The code is not working form me is this the right function am using??
![]()
Please Login or Register to view this content.
Last edited by royUK; 05-28-2008 at 11:21 AM.
You need to place the True part of the IF test on it's on line, rather than immediately after the THEN
What exactly is not working, assuming the change does not fix your problem.![]()
Please Login or Register to view this content.
How are you using it? Try the test I have added.
Also, please use Code Tags in future posts
![]()
Please Login or Register to view this content.
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
Hi guys thanks for that,
Ive just started learing how to use VB.
The task i was given was, in cells A1- A4 enter random years and in cells B1-B4 it would say true or false in the cell.
The Function works in a worksheet the same as inbuilt functions. Put the year 2008 in A1, in B1 =leapYear(A1). B1 should display true.
Hi there thanks for that its working fine.
Is there a code for the one you gave me in VB??
thanks again
I don't understand, I have given you an example how to use it in VBA earlier.Originally Posted by ianma
What i mean is,
In Cell A1- Cell A4 have to put in randon years for example:
1997
1998
2002
2008
then i want a VB code to tell me in cell B1- B4 if the year is a leap year or not.
So if yes it should state True and not it should state False.
You just put the years in column A and the formula in Column B as I explained earlier. Then copy the formula down in Column B
ive done it the way have showed me and it works.
I've been told that ive to use VB and not formattign cells
Here is the spreadsheet that ive to copy.
I no my teacher has used everything in vb the only things he has password protected vb so i cant copy his work.
If you put this spreadsheet formula in a cell, it will tell you if the date in A2 is in a leap year.
=IF(DAY(DATE(YEAR(A2),3,1)-1)=29,"Leap Year","Not")
if just a year is in A2, (i.e. A2 contains 2008 rather than 6/23/2008), that formula would be
=IF(DAY(DATE(A2,3,1)-1)=29,"Leap Year","Not")
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
You have the VBA & I have told you how to use it. What part do you not understand?Originally Posted by ianma
I can't open the attachedf workbook, try zipping it first.
Last edited by royUK; 06-02-2008 at 09:32 AM.
Hello ianma,
After reading your post and looking at the your teacher's code, it appears you need to create a VBA project that will automatically read down column "A" and test if the random years are leap years. Here is a macro to do that.
Adding the Macro![]()
Please Login or Register to view this content.
1. Copy the macro above pressing the keys CTRL+C
2. Open your workbook
3. Press the keys ALT+F11 to open the Visual Basic Editor
4. Press the keys ALT+I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL+V
7. Make any custom changes to the macro if needed at this time
8. Save the Macro by pressing the keys CTRL+S
9. Press the keys ALT+Q to exit the Editor, and return to Excel.
To Run the Macro...
To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Sincerely,
Leith Ross
ianma
You are not providing enough information. You have the code, your sheet contains the expected results. All you need to do is add the formula that i have already given you in Column C and the result should match Column B.
If this is not what you want tell us exactly what your teacher requires.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks