Capture Old Cell Value - VBA

redbaron06

New Member
Joined
Aug 6, 2010
Messages
44
Hi Everyone!

I would really appreciate some help with this one.

I am trying to hide a worksheet using the old value in a cell and then unhide another worksheet using new value in the cell. I want this event to be triggered by a change in cell "O11" (generated from a formula). I have tried a few different methods and have run into a roadblock. I cannot figure out how to save the previous value of the cell before the change to use later in the Sub.

Thanks in advance! - Terry

Private Sub Worksheet_Calculate()
Static OldVal1 As Variant, OldVal2 As Variant
If Range("O11").Value <> OldVal1 Then
With Worksheets(OldVal1)Visible
.Visible = xlSheetVeryHidden
End With

OldVal1 = Range("O11").Value
Call PlayTennis
With Worksheets(Range("O11").Value)
.Visible = xlSheetVisible
End With
End If
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Is it?

Code:
Private Sub Worksheet_Calculate()
    Static OldVal As Variant
    If IsEmpty(OldVal) Then OldVal = Range("O11").Value
    If Range("O11").Value <> OldVal Then
        Worksheets(OldVal).Visible = xlSheetVeryHidden
        OldVal = Range("O11").Value
        Call PlayTennis
        Worksheets(Range("O11").Value).Visible = xlSheetVisible
    End If
End Sub
 
Upvote 0
Thank you so much Andrew!

That solves the worksheet problem! However, it now prevents Call PlayTennis from running properly. I will tinker and see what I can do.

Sub PlayTennis()

RangeTango = Range("O11").Value
Sheets(Range("O11").Value).Activate
Range("A1:D50").Select
Selection.Copy Destination:=Sheets("Main").Range("A1")
Sheets("Main").Activate
End Sub
 
Upvote 0
Got it, thanks again!

Private Sub Worksheet_Calculate()
Static OldVal As Variant
If IsEmpty(OldVal) Then OldVal = Range("O11").Value
If Range("O11").Value <> OldVal Then
Worksheets(OldVal).Visible = xlSheetVeryHidden
OldVal = Range("O11").Value
Worksheets(Range("O11").Value).Visible = xlSheetVisible
Call PlayTennis
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,577
Members
449,318
Latest member
Son Raphon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top