Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Toggle Calculation Status

The purpose of the following code is to allow the user to toggle calculation
back and forth between auto and manual. When they click on the button, Cell
K20 says either automatic or manual, so they know what they changed it to.
Problem is that each time they open the file, when they click on the button
for the first time, Cell K20 doesn't update; they have to click on the button
again in order for K20 to update to the correct status. I can't seem to
figure out what I'm doing wrong. If someone has an idea, please enlighten
me! Thanks....Paige

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Toggle Calculation Status

Paige,

Change your first conditional:

Private Sub ToggleButton1_Click()
If Range("K20").Value = "MANUAL" Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
End Sub

HTH,
Bernie
MS Excel MVP


"Paige" wrote in message
...
The purpose of the following code is to allow the user to toggle calculation
back and forth between auto and manual. When they click on the button, Cell
K20 says either automatic or manual, so they know what they changed it to.
Problem is that each time they open the file, when they click on the button
for the first time, Cell K20 doesn't update; they have to click on the button
again in order for K20 to update to the correct status. I can't seem to
figure out what I'm doing wrong. If someone has an idea, please enlighten
me! Thanks....Paige

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Toggle Calculation Status


The focus is probably not on the active page.
After opening the file you need to perform a worksheets(abc).activate

Excel has lots of problems with the focus not being where you wnat it to be.

"Paige" wrote:

The purpose of the following code is to allow the user to toggle calculation
back and forth between auto and manual. When they click on the button, Cell
K20 says either automatic or manual, so they know what they changed it to.
Problem is that each time they open the file, when they click on the button
for the first time, Cell K20 doesn't update; they have to click on the button
again in order for K20 to update to the correct status. I can't seem to
figure out what I'm doing wrong. If someone has an idea, please enlighten
me! Thanks....Paige

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Toggle Calculation Status

Instead of altering a cell in the spreadsheet why not change the button
caption. That gets you around the whole sheet protection thing. Something
like this...

Private Sub ToggleButton1_Click()
If Application.Calculation = xlCalculationAutomatic Then
ToggleButton1.Caption = "Manual"
Application.Calculation = xlCalculationManual
Else
ToggleButton1.Caption = "Automatic"
Application.Calculation = xlCalculationAutomatic
End If
End Sub

You will want to ensure that the caption and calc mode are correct on open
something like this... (Place in ThisWorkbook)...

Private Sub Workbook_Open()
Application.Calculation = xlCalculationAutomatic
Sheet1.ToggleButton1.Caption = "Automatic"
End Sub

--
HTH...

Jim Thomlinson


"Paige" wrote:

The purpose of the following code is to allow the user to toggle calculation
back and forth between auto and manual. When they click on the button, Cell
K20 says either automatic or manual, so they know what they changed it to.
Problem is that each time they open the file, when they click on the button
for the first time, Cell K20 doesn't update; they have to click on the button
again in order for K20 to update to the correct status. I can't seem to
figure out what I'm doing wrong. If someone has an idea, please enlighten
me! Thanks....Paige

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Toggle Calculation Status

Wow! Thanks for all the quick responses. I will try them shortly and let
you know how they work. Thanks again....

"Jim Thomlinson" wrote:

Instead of altering a cell in the spreadsheet why not change the button
caption. That gets you around the whole sheet protection thing. Something
like this...

Private Sub ToggleButton1_Click()
If Application.Calculation = xlCalculationAutomatic Then
ToggleButton1.Caption = "Manual"
Application.Calculation = xlCalculationManual
Else
ToggleButton1.Caption = "Automatic"
Application.Calculation = xlCalculationAutomatic
End If
End Sub

You will want to ensure that the caption and calc mode are correct on open
something like this... (Place in ThisWorkbook)...

Private Sub Workbook_Open()
Application.Calculation = xlCalculationAutomatic
Sheet1.ToggleButton1.Caption = "Automatic"
End Sub

--
HTH...

Jim Thomlinson


"Paige" wrote:

The purpose of the following code is to allow the user to toggle calculation
back and forth between auto and manual. When they click on the button, Cell
K20 says either automatic or manual, so they know what they changed it to.
Problem is that each time they open the file, when they click on the button
for the first time, Cell K20 doesn't update; they have to click on the button
again in order for K20 to update to the correct status. I can't seem to
figure out what I'm doing wrong. If someone has an idea, please enlighten
me! Thanks....Paige

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Toggle Calculation Status

Tried them out; ended up going with Jim's idea so that the verbiage would
show on the button versus separately. Thanks again for the great feedback;
will keep it all for future reference/use.

"Paige" wrote:

Wow! Thanks for all the quick responses. I will try them shortly and let
you know how they work. Thanks again....

"Jim Thomlinson" wrote:

Instead of altering a cell in the spreadsheet why not change the button
caption. That gets you around the whole sheet protection thing. Something
like this...

Private Sub ToggleButton1_Click()
If Application.Calculation = xlCalculationAutomatic Then
ToggleButton1.Caption = "Manual"
Application.Calculation = xlCalculationManual
Else
ToggleButton1.Caption = "Automatic"
Application.Calculation = xlCalculationAutomatic
End If
End Sub

You will want to ensure that the caption and calc mode are correct on open
something like this... (Place in ThisWorkbook)...

Private Sub Workbook_Open()
Application.Calculation = xlCalculationAutomatic
Sheet1.ToggleButton1.Caption = "Automatic"
End Sub

--
HTH...

Jim Thomlinson


"Paige" wrote:

The purpose of the following code is to allow the user to toggle calculation
back and forth between auto and manual. When they click on the button, Cell
K20 says either automatic or manual, so they know what they changed it to.
Problem is that each time they open the file, when they click on the button
for the first time, Cell K20 doesn't update; they have to click on the button
again in order for K20 to update to the correct status. I can't seem to
figure out what I'm doing wrong. If someone has an idea, please enlighten
me! Thanks....Paige

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "AUTOMATIC"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
Else
Application.Calculation = xlCalculationManual
ActiveSheet.Unprotect Password:="xxxx"
Range("K20").Value = "MANUAL"
Range("E9").Select
ActiveSheet.Protect Password:="xxxx", DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Exit Sub
End If
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
How can I toggle in and out of read-only status in an Excel file? SS Excel Discussion (Misc queries) 3 April 11th 09 04:50 PM
Returning calculation status Phil H Excel Worksheet Functions 1 August 14th 08 06:03 PM
Status Bar with ETA calculation ExcelMonkey Excel Programming 4 July 30th 06 07:33 PM
Toggle calculation FJDx Excel Programming 3 July 19th 04 01:10 AM
Check calculation status Jeff Excel Programming 2 November 25th 03 04:23 PM


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