Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with user function please

I want the following function to return either a string
(in the form DDMMMYYYY or HHMM), or just a blank if the
parameter INDATE hasn't been completed. The date/time
adding bit works OK, but if INDATE is blank the function
returns #VALUE!. It wouldn't matter except that the
#VALUE! response causes problems with a seperate importing
program. Is there any way I can fix it?

(INDATE and INTIME are strings in the form DDMMMYYYY and
HHMM respectively)

Many thanks,
Geoff.

Function TxtDateAdd(INDATE As Variant, INTIME As Variant,
HOURS As Double, DH As String) As Variant
TxtDateAdd = IIf(VarType(INDATE) = 8, UCase(Format
(CDate(Mid(INDATE, 1, 2) & "-" & Mid(INDATE, 3, 3) & "-" &
Mid(INDATE, 6, 4)) + CDate(Mid(INTIME, 1, 2) & ":" & Mid
(INTIME, 3, 2)) + (HOURS / 24), IIf(DH = "D", "ddmmmyyyy",
IIf(DH = "H", "hhmm", "mmhhyydd")))), "" )
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Help with user function please

I re-wrote the function to make it clearer:-

Function TxtDateAdd(INDATE As String, _
INTIME As String, _
HOURS As Double, _
DH As String) As String
'Input:
'INDATE DDMMMYY
'INTIME HHMM
'HOURS - units
'DH D/H
Dim ThisDate As String, NewTime As Double

If INDATE < "" Then
ThisDate = Left(INDATE, 2) & "-" _
& Mid(INDATE, 3, 3) & "-" _
& Right(INDATE, 4) & " "
End If

ThisDate = ThisDate & Left(INTIME, 2) & ":" _
& Right(INTIME, 2)

NewTime = CDbl(TimeValue(ThisDate) _
+ DateValue(ThisDate)) _
+ HOURS / 24
If DH = "D" Then

TxtDateAdd = Format$(NewTime, "ddmmmyyyy hh:mm")

Else

TxtDateAdd = Format$(NewTime, "hh:mm")

End If
End Function

Patrick Molloy
Microsft Excel MVP


-----Original Message-----
I want the following function to return either a string
(in the form DDMMMYYYY or HHMM), or just a blank if the
parameter INDATE hasn't been completed. The date/time
adding bit works OK, but if INDATE is blank the function
returns #VALUE!. It wouldn't matter except that the
#VALUE! response causes problems with a seperate

importing
program. Is there any way I can fix it?

(INDATE and INTIME are strings in the form DDMMMYYYY and
HHMM respectively)

Many thanks,
Geoff.

Function TxtDateAdd(INDATE As Variant, INTIME As

Variant,
HOURS As Double, DH As String) As Variant
TxtDateAdd = IIf(VarType(INDATE) = 8, UCase(Format
(CDate(Mid(INDATE, 1, 2) & "-" & Mid(INDATE, 3, 3) & "-"

&
Mid(INDATE, 6, 4)) + CDate(Mid(INTIME, 1, 2) & ":" & Mid
(INTIME, 3, 2)) + (HOURS / 24), IIf(DH

= "D", "ddmmmyyyy",
IIf(DH = "H", "hhmm", "mmhhyydd")))), "" )
End Function

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with user function please

Many thanks, this will improve my function writing a lot!

-----Original Message-----
I re-wrote the function to make it clearer:-

Function TxtDateAdd(INDATE As String, _
INTIME As String, _
HOURS As Double, _
DH As String) As String
'Input:
'INDATE DDMMMYY
'INTIME HHMM
'HOURS - units
'DH D/H
Dim ThisDate As String, NewTime As Double

If INDATE < "" Then
ThisDate = Left(INDATE, 2) & "-" _
& Mid(INDATE, 3, 3) & "-" _
& Right(INDATE, 4) & " "
End If

ThisDate = ThisDate & Left(INTIME, 2) & ":" _
& Right(INTIME, 2)

NewTime = CDbl(TimeValue(ThisDate) _
+ DateValue(ThisDate)) _
+ HOURS / 24
If DH = "D" Then

TxtDateAdd = Format$(NewTime, "ddmmmyyyy hh:mm")

Else

TxtDateAdd = Format$(NewTime, "hh:mm")

End If
End Function

Patrick Molloy
Microsft Excel MVP


-----Original Message-----
I want the following function to return either a string
(in the form DDMMMYYYY or HHMM), or just a blank if the
parameter INDATE hasn't been completed. The date/time
adding bit works OK, but if INDATE is blank the function
returns #VALUE!. It wouldn't matter except that the
#VALUE! response causes problems with a seperate

importing
program. Is there any way I can fix it?

(INDATE and INTIME are strings in the form DDMMMYYYY and
HHMM respectively)

Many thanks,
Geoff.

Function TxtDateAdd(INDATE As Variant, INTIME As

Variant,
HOURS As Double, DH As String) As Variant
TxtDateAdd = IIf(VarType(INDATE) = 8, UCase(Format
(CDate(Mid(INDATE, 1, 2) & "-" & Mid(INDATE, 3, 3) & "-"

&
Mid(INDATE, 6, 4)) + CDate(Mid(INTIME, 1, 2) & ":" & Mid
(INTIME, 3, 2)) + (HOURS / 24), IIf(DH

= "D", "ddmmmyyyy",
IIf(DH = "H", "hhmm", "mmhhyydd")))), "" )
End Function

.

.

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
user defined function tom_mcd Excel Worksheet Functions 1 January 6th 09 06:23 PM
sumproduct function / VB user defined function aw Excel Discussion (Misc queries) 3 September 23rd 08 09:05 AM
User Defined FUNCTION EAK Excel Discussion (Misc queries) 5 July 17th 08 07:07 PM
User-defined function PierreL Excel Worksheet Functions 4 December 23rd 04 09:16 AM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 07:10 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"