UDF Find Date - Page 3


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

 
 
Thread Tools Rate Thread Display Modes
  #21  
Old 3rd March 2014, 13:56
LisaGreen's Avatar
LisaGreen LisaGreen is offline
Solution Centre Professional
MS Office Version: MS Office 97, 2003, 2007,2010
MS Office Skill Level: Can use VBA
 
Join Date: Jun 2011
Location: Houten, Nederlands
Age: 66
Posts: 568
Posts Per Day: 0.24
My Top Tip Count: 1
Thanks to others: 9
Thanked 18 Times in 16 Posts
Reputation: 270 (14) LisaGreen is a jewel in the roughLisaGreen is a jewel in the roughLisaGreen is a jewel in the rough
1 Top Tips
Great_Britain
Default Re: UDF Find Date


------ Register to get rid of these "In Post" ads! ------


Hi Roy,

I could be wrong here but I think that the function you sent returns TRUE because it hasn't found a date that is there????

Lisa



The Code Cage Advertisment
Advertisement
  #22  
Old 5th March 2014, 13:56
Rory's Avatar
Rory Rory is offline
Solution Centre Professional
MS Office Version: 2003 onwards
MS Office Skill Level: Competent technician
 
Join Date: Feb 2010
Location: Ubique
Age: 27
Posts: 871
Posts Per Day: 0.31
My Top Tip Count: 2
Thanks to others: 0
Thanked 112 Times in 109 Posts
Reputation: 1963 (35) Rory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant futureRory has a brilliant future
2 Top Tips
Northern_Ireland
Default Re: UDF Find Date

------ Register to get rid of these "In Post" ads! ------


A UDF called by VBA will, in typical VBA fashion, assume a US-centric attitude and therefore accept US formatted dates. Called from a worksheet cell, it will respect user settings. Hence the test routine returns False for me (UK settings) whereas the cell returns True, since it's looking for "2/27/2014" but the formula bar shows 27/02/2014. If I change the find string to match the formula bar, the Cell returns False but test now returns True.
__________________
Rory
Microsoft MVP - Excel

Always listen to advice, even if you don't take it.



  #23  
Old 6th March 2014, 13:06
Jack in the UK's Avatar
Jack in the UK Jack in the UK is offline
The Code Cage Staff
MS Office Version: MS Office 97, 2003, 2007,2010
MS Office Skill Level: Proficient with Excel
 
Join Date: Dec 2011
Location: England
Posts: 545
Posts Per Day: 0.25
My Top Tip Count: 0
Thanks to others: 3
Thanked 43 Times in 43 Posts
Reputation: 570 (16) Jack in the UK is a name known to allJack in the UK is a name known to allJack in the UK is a name known to allJack in the UK is a name known to allJack in the UK is a name known to allJack in the UK is a name known to all
England
Default Re: UDF Find Date

------ Register to get rid of these "In Post" ads! ------


The is why you need to write robust codes, not fixes as that will only end in pain sooner

With all functions they can (should) only return a value nothing else

Text = label
Number = value

false - flag (value)
True = flag (value)

Note false is always first and is in fact in VB / VBA is the standard default i.e. a code without a flag will report always false, otherwise it will fail, unless the codes forcing things backwards but that's a separate issue

BUT - good practice is first live code after declaration =

VBA CODE:
 ' jiuk - code line (example)
 
Dim x As Long 
 
Set myFuncyion = False 

This way the test are know results, ie FALSE is always expected. To prove this further
** caution the isdate is not totally robust and know to be floored, however will give good test results
VBA CODE:
Function myIS_IT_a_DATE(target_CELL As Excel.Range) 
     '// written by: Jack in the UK 06/03/2014
     '// The Code Cage Forums
     '// http://www.thecodecage.com/forumz/sh...=214585&page=3
     
     '// Function Requirde - Edit as required (range only from B5/6 as used in Jacks tests)
     '// =myIS_IT_a_DATE(B5)
     
    myIS_IT_a_DATE = False 
     '// jiuk - NOTE forced to negative flag
     
    If IsDate(target_CELL) Then 
        myIS_IT_a_DATE = "This is a date" 
    ElseIf IsNumeric(target_CELL) Then 
        myIS_IT_a_DATE = "Is a date" 
    Else 
        myIS_IT_a_DATE = "Not a date" 
    End If 
theEND_myIS_IT_a_DATE: 
     '// jiuk
     '// do something
    Exit Function 
     
End Function 


Using the above with English UK vs English US formatted dates d & M transposed. Both results will report back 'is a date'. Be very careful with times add into the equation things are handled differently and can get funky indeed

This function will also test for you, this is quite robust
VBA CODE:
=If(Not(ISERROR(DATEVALUE(TEXT(B5,"mm/dd/yyyy")))),"Is Date","Not a DATE") 


As Jack always says, depends what you want to do and how

jiuk
__________________
VBA CODE:
Regards, 
Jack In the UK 



The Code Cage Advertisment
Advertisement
 
The Code Cage at Facebookhe Code Cage at Twitter


Tags
date, udf

Thread Tools
Display Modes 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

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 07:46.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University
X vBulletin 3.8.7 Debug Information
  • Page Generation 0.18416 seconds
  • Memory Usage 6,404KB
  • Queries Executed 17 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footerEnd
  • (1)ad_footerStart
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_headerEnd
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_leftcolumn_code
  • (1)ad_navbar_below
  • (2)ad_postbit_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (3)helpful_answers
  • (1)helpfulanswers_javascript
  • (1)navbar
  • (3)navbar_link
  • (3)navbar_noticebit
  • (52)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (3)post_thanks_box
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_ctoptip
  • (3)postbit_onlinestatus
  • (20)postbit_reputation
  • (3)postbit_wrapper
  • (1)showthread_changepostsowner_link
  • (1)showthread_quickreply_mrgdp
  • (1)showthread_reason_popup
  • (1)spacer_close
  • (1)spacer_open
  • (1)su_form
  • (2)tagbit
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_datastore.php
  • ./includes/class_hook.php
  • ./awcoding/plugins/awc.php
  • ./awcoding/plugins/ds.php
  • ./awcoding/plugins/ss.php
  • ./includes/functions_notice.php
  • ./mobiquo/smartbanner.php
  • ./mobiquo/include/classTTConnection.php
  • ./mobiquo/smartbanner/head.inc.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/vbatags.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php
  • ./includes/functions_misc.php 

Hooks Called:
  • init_startup
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_check_criteria
  • notices_noticebit
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • helpfulanswers_showthreadorpost
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • helpfulanswers_show_normal
  • reputation_power
  • reputation_image
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • error_fetch
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete