Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Preformatted array returned by custom function

I've created a function that returns an array of numbers which I'd like to
be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Preformatted array returned by custom function

I think you would need to format the range in the correct format. A
worksheet function cannot make any formatting changes.

--

Vasant

"Asif" wrote in message
...
I've created a function that returns an array of numbers which I'd like to
be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Preformatted array returned by custom function

Well Vasant-ji, thanks for your reply. But I think a function can directly
return numbers in "##,##0" format when it returns a single value.

Function NumberFormatting(theNumber)
theNumber=10000.01
NumberFormatting=Format(theNumber,"##,##0")
End Function

I'd like to do something similar with my function that returns an array.

Thanks
~Asif



Vasant Nanavati wrote in message ...
I think you would need to format the range in the correct format. A
worksheet function cannot make any formatting changes.

--

Vasant

"Asif" wrote in message
...
I've created a function that returns an array of numbers which I'd like

to
be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Preformatted array returned by custom function

A simple sample:

Function testIt()
Dim arr, i As Long, Elem as variant
arr = Array(1000.01, 10000.01, 100000.01)
i = 1
For Each Elem In arr
arr(i) = Format(Elem, "##,##0")
i = i + 1
Next
testIt = arr
End Function

Array enter =testIt() into a range of cells of the appropriate size and
shape to accommodate the output.

Alan Beban

Asif wrote:
Well Vasant-ji, thanks for your reply. But I think a function can directly
return numbers in "##,##0" format when it returns a single value.

Function NumberFormatting(theNumber)
theNumber=10000.01
NumberFormatting=Format(theNumber,"##,##0")
End Function

I'd like to do something similar with my function that returns an array.

Thanks
~Asif



Vasant Nanavati wrote in message ...

I think you would need to format the range in the correct format. A
worksheet function cannot make any formatting changes.

--

Vasant

"Asif" wrote in message
...

I've created a function that returns an array of numbers which I'd like


to

be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Preformatted array returned by custom function

Sorry, I misunderstood your question. Of course you can use the format
function to format the number, but what will be returned is a string, not a
number. If that is acceptable, Alan's solution will do what you need.

--

Vasant



"Asif" wrote in message
...
Well Vasant-ji, thanks for your reply. But I think a function can directly
return numbers in "##,##0" format when it returns a single value.

Function NumberFormatting(theNumber)
theNumber=10000.01
NumberFormatting=Format(theNumber,"##,##0")
End Function

I'd like to do something similar with my function that returns an array.

Thanks
~Asif



Vasant Nanavati wrote in message ...
I think you would need to format the range in the correct format. A
worksheet function cannot make any formatting changes.

--

Vasant

"Asif" wrote in message
...
I've created a function that returns an array of numbers which I'd like

to
be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Preformatted array returned by custom function

Vasant Nanavati wrote:
Sorry, I misunderstood your question. Of course you can use the format
function to format the number, but what will be returned is a string, not a
number. If that is acceptable, Alan's solution will do what you need.


And if it's not, then I believe calling it with =--testIt() will.

Alan Beban

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Preformatted array returned by custom function

=--testit()
removes the formatting produced by the function.

--
Regards,
Tom Ogilvy

Alan Beban wrote in message
...
Vasant Nanavati wrote:
Sorry, I misunderstood your question. Of course you can use the format
function to format the number, but what will be returned is a string,

not a
number. If that is acceptable, Alan's solution will do what you need.


And if it's not, then I believe calling it with =--testIt() will.

Alan Beban



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Preformatted array returned by custom function

Unless you have option Base 1,
arr is zero based.

Function testIt()
Dim arr, i As Long, Elem as variant
arr = Array(1000.01, 10000.01, 100000.01)
i = lbound(arr)
For Each Elem In arr
arr(i) = Format(Elem, "##,##0")
i = i + 1
Next
testIt = arr
End Function

Might be a little more robust.

--
Regards,
Tom Ogilvy


Alan Beban wrote in message
...
A simple sample:

Function testIt()
Dim arr, i As Long, Elem as variant
arr = Array(1000.01, 10000.01, 100000.01)
i = 1
For Each Elem In arr
arr(i) = Format(Elem, "##,##0")
i = i + 1
Next
testIt = arr
End Function

Array enter =testIt() into a range of cells of the appropriate size and
shape to accommodate the output.

Alan Beban

Asif wrote:
Well Vasant-ji, thanks for your reply. But I think a function can

directly
return numbers in "##,##0" format when it returns a single value.

Function NumberFormatting(theNumber)
theNumber=10000.01
NumberFormatting=Format(theNumber,"##,##0")
End Function

I'd like to do something similar with my function that returns an array.

Thanks
~Asif



Vasant Nanavati wrote in message ...

I think you would need to format the range in the correct format. A
worksheet function cannot make any formatting changes.

--

Vasant

"Asif" wrote in message
...

I've created a function that returns an array of numbers which I'd like

to

be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Preformatted array returned by custom function

Indeed it does. The cells I used in testing it happened to be formatted
to produce the right result. Sloppy.

Thanks,
Alan Beban

Tom Ogilvy wrote:
=--testit()
removes the formatting produced by the function.

--
Regards,
Tom Ogilvy

Alan Beban wrote in message
...

Vasant Nanavati wrote:

Sorry, I misunderstood your question. Of course you can use the format
function to format the number, but what will be returned is a string,


not a

number. If that is acceptable, Alan's solution will do what you need.


And if it's not, then I believe calling it with =--testIt() will.

Alan Beban





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Preformatted array returned by custom function

Tom Ogilvy wrote:
Unless you have option Base 1,
arr is zero based.


I did, and the loop assumes a 1-based array. To avoid the assumption,
the array needs to be loaded more rigorously.

Alan Beban


Function testIt()
Dim arr, i As Long, Elem as variant
arr = Array(1000.01, 10000.01, 100000.01)
i = lbound(arr)
For Each Elem In arr
arr(i) = Format(Elem, "##,##0")
i = i + 1
Next
testIt = arr
End Function

Might be a little more robust.

--
Regards,
Tom Ogilvy


Alan Beban wrote in message
...

A simple sample:

Function testIt()
Dim arr, i As Long, Elem as variant
arr = Array(1000.01, 10000.01, 100000.01)
i = 1
For Each Elem In arr
arr(i) = Format(Elem, "##,##0")
i = i + 1
Next
testIt = arr
End Function

Array enter =testIt() into a range of cells of the appropriate size and
shape to accommodate the output.

Alan Beban

Asif wrote:

Well Vasant-ji, thanks for your reply. But I think a function can


directly

return numbers in "##,##0" format when it returns a single value.

Function NumberFormatting(theNumber)
theNumber=10000.01
NumberFormatting=Format(theNumber,"##,##0")
End Function

I'd like to do something similar with my function that returns an array.

Thanks
~Asif



Vasant Nanavati wrote in message ...


I think you would need to format the range in the correct format. A
worksheet function cannot make any formatting changes.

--

Vasant

"Asif" wrote in message
.. .


I've created a function that returns an array of numbers which I'd like

to


be shown in "##,##0" format when the array is printed to the worksheet.
Looks like I can't do this. Can I?

Thanks
~Asif








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
Want to open worksheet in preformatted style Darrell Hillis, CPA Setting up and Configuration of Excel 1 September 16th 08 12:09 AM
Getting a list of returned values from an array ProfMarks Excel Worksheet Functions 1 January 23rd 08 04:17 AM
array results not returned JRM-drof Excel Worksheet Functions 2 June 27th 06 06:46 PM
Excel SQL.Request restricts data returned to array GTSA Excel Worksheet Functions 4 January 11th 05 12:49 AM
returning an array from a custom function Ron Davis Excel Programming 2 September 15th 03 11:02 AM


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