Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with range in vba function

I have that code

public function toto(r as Range) as long
dim i as long

for i = 1 to r.count
toto = toto + r.Cells(1,i).value
if r.Cells(1,i).value < 10 then
r.Cells(1,i).select
with selection.font
.Strikethrough = True
End With
end if
next i

end function

if I'm in the execution window i can type ?toto(activesheet.range("A1:A12"))
that works fine

but if in a cell I type =toto("A1:A12") the fonction does sum the values but
the select and the strikethrough does'nt work.

thanks
Cédric


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default help with range in vba function


I can tell you why it doesn't work, but I'm not sure of
the solution. When a function is calculated in a cell,
that cell remains selected until the function has finished
its calculation. So the Select statements in the function
cannot work.

You could put the code into a sub instead, and get it to
put the sum into the cell below the range.

Hope this helps,
Helen

-----Original Message-----
I have that code

public function toto(r as Range) as long
dim i as long

for i = 1 to r.count
toto = toto + r.Cells(1,i).value
if r.Cells(1,i).value < 10 then
r.Cells(1,i).select
with selection.font
.Strikethrough = True
End With
end if
next i

end function

if I'm in the execution window i can type ?toto

(activesheet.range("A1:A12"))
that works fine

but if in a cell I type =toto("A1:A12") the fonction does

sum the values but
the select and the strikethrough does'nt work.

thanks
Cédric


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default help with range in vba function

A function can only return a value to the cell
(or array of cells), from which it was called.
It cannot make any changes to a cell.

--
Best Regards
Leo Heuser
MVP Excel

Followup to newsgroup only please.

"Helen Trim" skrev i en meddelelse
...

I can tell you why it doesn't work, but I'm not sure of
the solution. When a function is calculated in a cell,
that cell remains selected until the function has finished
its calculation. So the Select statements in the function
cannot work.

You could put the code into a sub instead, and get it to
put the sum into the cell below the range.

Hope this helps,
Helen

-----Original Message-----
I have that code

public function toto(r as Range) as long
dim i as long

for i = 1 to r.count
toto = toto + r.Cells(1,i).value
if r.Cells(1,i).value < 10 then
r.Cells(1,i).select
with selection.font
.Strikethrough = True
End With
end if
next i

end function

if I'm in the execution window i can type ?toto

(activesheet.range("A1:A12"))
that works fine

but if in a cell I type =toto("A1:A12") the fonction does

sum the values but
the select and the strikethrough does'nt work.

thanks
Cédric


.



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
If function and a range mrsatroy Excel Worksheet Functions 4 March 16th 10 05:07 PM
Range of a function Daniel Excel Discussion (Misc queries) 3 September 18th 07 08:48 AM
DBSUM function but with function as criterion, not a range corne_mo Excel Worksheet Functions 3 July 13th 07 12:20 PM
range function Felicia Excel Discussion (Misc queries) 2 January 29th 07 06:10 PM
Between/ range function sanpanico Excel Discussion (Misc queries) 3 April 28th 05 10:25 PM


All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"