#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default volatile

I have a function that i need to be volatile, but when i run a short
macro that usually takes about 30 seconds with this function as
volatile it takes a long time to run ( i have never bothered even
letting it complete). I wanted to do boolean logic and an if then but
this doesnt seem to work any ideas on how to have a function not
recalculate when a macro is running but recalculate when it is not?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default volatile

Please be more specific; What is the code of your macro and of your function? Under what conditions is your macro executed? etc.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

wrote in message ...
|I have a function that i need to be volatile, but when i run a short
| macro that usually takes about 30 seconds with this function as
| volatile it takes a long time to run ( i have never bothered even
| letting it complete). I wanted to do boolean logic and an if then but
| this doesnt seem to work any ideas on how to have a function not
| recalculate when a macro is running but recalculate when it is not?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default volatile

Macro is only executed when a button is pressed.

Code:

Private Function state(sheet, row, column)

Application.Volatile

state = Sheets(sheet).Cells(row,
WorksheetFunction.VLookup(WorksheetFunction.VLooku p(Sheets("dummy
state").Range("c3"), Sheets("io").Range("alphastate"), 2),
Sheets("io").Range("columns"), column, 0))


End Function

This runs when button is pressed:

Sub hideshowstates()

Application.ScreenUpdating = False

For j = 1 To 2

For i = 6 To 30
If Sheets("Basic Data").Cells(i, j) = "True" Then ' show
in projections sheets
For z = 2 To 28
sht = Sheets("io").Cells(2, z)
If j = 1 Then
col = Sheets("io").Cells(i - 2, z)
Sheets(2).Rows(i + 11).Hidden = False ' show
on percentages sheet
Else
col = Sheets("io").Cells(i + 23, z)
Sheets(2).Rows(i + 36).Hidden = False ' show
on percentages sheet
End If
Sheets(sht).Columns(col).Hidden = False
Next z


Else
For z = 2 To 28 ' hide on projections sheets
sht = Sheets("io").Cells(2, z)
If j = 1 Then
col = Sheets("io").Cells(i - 2, z)
Sheets(2).Rows(i + 11).Hidden = True ' hide on
percentages sheet
For r = 2 To 10
Sheets(2).Cells(i + 11, r).ClearContents
Next r
Else

col = Sheets("io").Cells(i + 23, z)
Sheets(2).Rows(i + 36).Hidden = True ' hide on
percentages sheet
For r = 2 To 10
Sheets(2).Cells(i + 36, r).ClearContents
Next r

End If
Sheets(sht).Columns(col).Hidden = True
Next z
End If

Next i
Next j

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default volatile

Try this:

Start your macro wit
Application.Calculation = xlManual
and end it with
Application.Calculation = xlAutomatic

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

wrote in message ...
| Macro is only executed when a button is pressed.
|
| Code:
|
| Private Function state(sheet, row, column)
|
| Application.Volatile
|
| state = Sheets(sheet).Cells(row,
| WorksheetFunction.VLookup(WorksheetFunction.VLooku p(Sheets("dummy
| state").Range("c3"), Sheets("io").Range("alphastate"), 2),
| Sheets("io").Range("columns"), column, 0))
|
|
| End Function
|
| This runs when button is pressed:
|
| Sub hideshowstates()
|
| Application.ScreenUpdating = False
|
| For j = 1 To 2
|
| For i = 6 To 30
| If Sheets("Basic Data").Cells(i, j) = "True" Then ' show
| in projections sheets
| For z = 2 To 28
| sht = Sheets("io").Cells(2, z)
| If j = 1 Then
| col = Sheets("io").Cells(i - 2, z)
| Sheets(2).Rows(i + 11).Hidden = False ' show
| on percentages sheet
| Else
| col = Sheets("io").Cells(i + 23, z)
| Sheets(2).Rows(i + 36).Hidden = False ' show
| on percentages sheet
| End If
| Sheets(sht).Columns(col).Hidden = False
| Next z
|
|
| Else
| For z = 2 To 28 ' hide on projections sheets
| sht = Sheets("io").Cells(2, z)
| If j = 1 Then
| col = Sheets("io").Cells(i - 2, z)
| Sheets(2).Rows(i + 11).Hidden = True ' hide on
| percentages sheet
| For r = 2 To 10
| Sheets(2).Cells(i + 11, r).ClearContents
| Next r
| Else
|
| col = Sheets("io").Cells(i + 23, z)
| Sheets(2).Rows(i + 36).Hidden = True ' hide on
| percentages sheet
| For r = 2 To 10
| Sheets(2).Cells(i + 36, r).ClearContents
| Next r
|
| End If
| Sheets(sht).Columns(col).Hidden = True
| Next z
| End If
|
| Next i
| Next j
|
| End Sub
|


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
volatile v non-volatile CJ Excel Discussion (Misc queries) 4 February 12th 10 12:16 PM
INDEX - volatile or not? T. Valko Excel Worksheet Functions 8 February 23rd 07 07:24 PM
Application.Volatile Nader Excel Programming 3 June 9th 06 04:14 PM
Need for Application.Volatile? Paul Lautman Excel Programming 2 August 19th 04 10:43 PM
Detect any Volatile UDF Sandy V[_4_] Excel Programming 4 October 23rd 03 01:26 PM


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