ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Invalid "format string" argument in Format fuction (https://www.excelbanter.com/excel-programming/331779-invalid-format-string-argument-format-fuction.html)

jjk

Invalid "format string" argument in Format fuction
 
Hi,

I was wondering if there is any way to check for invalid "format
string" argument in the Format function.
As far as I can see it accepts all string combinations. Is there any
exception handling or boounds check that I can place here.
I ask this because I have to wrap the format functionality and want to
watch out for any side effects.

Thanks,
Jayant

Ref from Help:

Format Function
Returns a Variant (String) containing an expression formatted according
to instructions contained in a format expression.

Syntax:
Format(expression[, format[, firstdayofweek[, firstweekofyear]]])

expression - Required. Any valid expression.
format - Optional. A valid named or user-defined format expression.
firstdayofweek - Optional. A constant that specifies the first day of
the week.
firstweekofyear - Optional. A constant that specifies the first week of
the year.


Leith Ross[_38_]

Invalid "format string" argument in Format fuction
 

Hello Jayant,

You can include an Error handler in your code.

EXAMPLE;

Sub FormatData()

On Error Goto FormatError

Text = Format(<String, <Format)

Exit Sub

FormatError:

MsgBox "The Format specified is Invalid", vbOKOnly + vbCritical

End Sub

In the code, "FormatError:" is a Line Label and must not haveany spaces
before it.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=379089


jjk

Invalid "format string" argument in Format fuction
 
Thanks Leith.

I was wondering if there is any list/formula for invalid formats.
The Format method works for any gibberish specified as format without
throwing an exception or error.

Regards,
Jayant


Tom Ogilvy

Invalid "format string" argument in Format fuction
 
VBA help has a list of valid characters and symbols and what they are used
for. In xl97 at least, there are several help topics with lists depending
on what you are formating - numbers, dates.

--
Regards,
Tom Ogilvy


"jjk" wrote in message
ups.com...
Thanks Leith.

I was wondering if there is any list/formula for invalid formats.
The Format method works for any gibberish specified as format without
throwing an exception or error.

Regards,
Jayant





All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com