I am trying set to the Calculation Property of each worksheet in a workbook independently with a macro. The user identifies worksheets where Calculation is to be enabled using a Listbox. The user then clicks a button to call the macro to apply the desired settings. Here is my code for Enabling Worksheet Calculation:
It only works (and works as intended for all worksheets) when ListBoxWorksheets.Selected(0) is TRUE. For example, these values produce the expected result:
I have verified that ListBoxWorksheets.Selected(i) produces the expected series of TRUE/FALSE such as TRUE, TRUE, FALSE, TRUE... with a MsgBox. Any guess as to what the problem may be?
VBA Code:
Private Sub EnableCalc()
Dim ws As Worksheet
Dim i As Long
For Each ws In ThisWorkbook.Worksheets
ws.EnableCalculation = ListBoxWorksheets.Selected(i)
i = i + 1
Next ws
End Sub
It only works (and works as intended for all worksheets) when ListBoxWorksheets.Selected(0) is TRUE. For example, these values produce the expected result:
ListBoxWorksheets.Selected(0) = TRUE
ListBoxWorksheets.Selected(1) = FALSE
ListBoxWorksheets.Selected(2) = FALSE
ListBoxWorksheets.Selected(3) = TRUE
If ListBoxWorksheets.Selected(0) is FALSE, the Calculation Property of all worksheets is set to FALSE not matter what the ListBoxWorksheets.Selected values are. For example, these values set the Calculation Property of all worksheets to FALSE:ListBoxWorksheets.Selected(0) = FALSE
ListBoxWorksheets.Selected(1) = TRUE
ListBoxWorksheets.Selected(2) = TRUE
ListBoxWorksheets.Selected(3) = TRUE
I have verified that ListBoxWorksheets.Selected(i) produces the expected series of TRUE/FALSE such as TRUE, TRUE, FALSE, TRUE... with a MsgBox. Any guess as to what the problem may be?