PC Review


Reply
Thread Tools Rate Thread

Application.Volatile not working

 
 
=?Utf-8?B?SmFz?=
Guest
Posts: n/a
 
      14th Sep 2007
Hi All,
I have the following macro that concatenates a range of cells, but it doesnt
auto-caculate. I have put Application.Volatile into the code but it still
doesnt work. Can someone help? (The macro is contained within a normal
module). I have also tried changing the function to "Public Function" and
that doesnt seem to work either...


Function Concat(myRange As Range, Optional myDelimiter As String)

Application.Volatile

Dim r As Range

For Each r In myRange
Concat = Concat & r & myDelimiter
Next r
If Len(myDelimiter) > 0 Then
Concat = Left(Concat, Len(Concat) - Len(myDelimiter))
End If

End Function



Any advice would be appreciated!
Thanks



 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFz?=
Guest
Posts: n/a
 
      14th Sep 2007
Really sorry for wasting anyone's time, but the spreadsheet calculation was
set to manual. I have changed this to automatic and this works fine.

"Jas" wrote:

> Hi All,
> I have the following macro that concatenates a range of cells, but it doesnt
> auto-caculate. I have put Application.Volatile into the code but it still
> doesnt work. Can someone help? (The macro is contained within a normal
> module). I have also tried changing the function to "Public Function" and
> that doesnt seem to work either...
>
>
> Function Concat(myRange As Range, Optional myDelimiter As String)
>
> Application.Volatile
>
> Dim r As Range
>
> For Each r In myRange
> Concat = Concat & r & myDelimiter
> Next r
> If Len(myDelimiter) > 0 Then
> Concat = Left(Concat, Len(Concat) - Len(myDelimiter))
> End If
>
> End Function
>
>
>
> Any advice would be appreciated!
> Thanks
>
>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      14th Sep 2007
You don't need Application.volatile in this code and you should probably
remove it to save on overhead. By including the range as a parameter XL will
trach changes to the percident cells and recalc this formula as necessary...
--
HTH...

Jim Thomlinson


"Jas" wrote:

> Really sorry for wasting anyone's time, but the spreadsheet calculation was
> set to manual. I have changed this to automatic and this works fine.
>
> "Jas" wrote:
>
> > Hi All,
> > I have the following macro that concatenates a range of cells, but it doesnt
> > auto-caculate. I have put Application.Volatile into the code but it still
> > doesnt work. Can someone help? (The macro is contained within a normal
> > module). I have also tried changing the function to "Public Function" and
> > that doesnt seem to work either...
> >
> >
> > Function Concat(myRange As Range, Optional myDelimiter As String)
> >
> > Application.Volatile
> >
> > Dim r As Range
> >
> > For Each r In myRange
> > Concat = Concat & r & myDelimiter
> > Next r
> > If Len(myDelimiter) > 0 Then
> > Concat = Left(Concat, Len(Concat) - Len(myDelimiter))
> > End If
> >
> > End Function
> >
> >
> >
> > Any advice would be appreciated!
> > Thanks
> >
> >
> >

 
Reply With Quote
 
=?Utf-8?B?SmFz?=
Guest
Posts: n/a
 
      14th Sep 2007
Handy tip - thanks Jim

"Jim Thomlinson" wrote:

> You don't need Application.volatile in this code and you should probably
> remove it to save on overhead. By including the range as a parameter XL will
> trach changes to the percident cells and recalc this formula as necessary...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Jas" wrote:
>
> > Really sorry for wasting anyone's time, but the spreadsheet calculation was
> > set to manual. I have changed this to automatic and this works fine.
> >
> > "Jas" wrote:
> >
> > > Hi All,
> > > I have the following macro that concatenates a range of cells, but it doesnt
> > > auto-caculate. I have put Application.Volatile into the code but it still
> > > doesnt work. Can someone help? (The macro is contained within a normal
> > > module). I have also tried changing the function to "Public Function" and
> > > that doesnt seem to work either...
> > >
> > >
> > > Function Concat(myRange As Range, Optional myDelimiter As String)
> > >
> > > Application.Volatile
> > >
> > > Dim r As Range
> > >
> > > For Each r In myRange
> > > Concat = Concat & r & myDelimiter
> > > Next r
> > > If Len(myDelimiter) > 0 Then
> > > Concat = Left(Concat, Len(Concat) - Len(myDelimiter))
> > > End If
> > >
> > > End Function
> > >
> > >
> > >
> > > Any advice would be appreciated!
> > > Thanks
> > >
> > >
> > >

 
Reply With Quote
 
Bill Renaud
Guest
Posts: n/a
 
      15th Sep 2007
The line:

Concat = Concat & r & myDelimiter

is calling the function recursively (with no arguments!). VBA allows
this type of statement, but I think it is generally better programming
practice to declare a local variable to use to concantenate the strings
together, then assign to the function at the end of the routine, like
so:

Function Concat(myRange As Range, Optional myDelimiter As String)
Dim strTemp As String
Dim r As Range

strTemp = ""
For Each r In myRange
strTemp = strTemp & r & myDelimiter
Next r

If Len(myDelimiter) > 0 Then
Concat = Left(strTemp, Len(strTemp) - Len(myDelimiter))
End If
End Function

--
Regards,
Bill Renaud



 
Reply With Quote
 
 
 
Reply

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Volatile False doesn't work with Application.Run? Hank Scorpio Microsoft Excel Programming 1 30th Aug 2009 04:04 PM
Application.Volatile False doesn't work with Application.Run? Hank Scorpio Microsoft Excel Misc 1 30th Aug 2009 04:04 PM
Call Application.Volatile(True) NOT WORKING FARAZ QURESHI Microsoft Excel Misc 1 8th May 2008 04:50 AM
Application.Volatile Not Working Timely FARAZ QURESHI Microsoft Excel Misc 2 10th Mar 2008 09:52 AM
Application.Volatile not working as expected =?Utf-8?B?UmljaGFyZHM=?= Microsoft Excel Misc 3 3rd Feb 2005 12:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 PM.