How can I make VB Code run when cell is changed by a formula?

babyg

New Member
Joined
Feb 27, 2009
Messages
24
I have code that runs 4 macros to hide and unhide sheets when the value of a cell changes. I have it set up so that when a user selects a value from the listbox a formula in a hidden cell changes to either a 1 or 0 depending on the value selected. The problem is unless I manually click on the formula cell the code doesn't run. How can I automate it so that my code recognizes the value in the cell changed without having to double click it?

Here is the code I am using:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Cells.Count > 1 Then Exit Sub
If IsNumeric(Target) And Target.Address = "$A$20" Then
Select Case Target.Value
Case Is = 0
Run "ShowAdminSheets"
Run "HideUserSheets"
Case Is = 1
Run "HideAdminSheets"
Run "ShowUserSheets"
End Select
End If
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Change it to:

Code:
  Private Sub Worksheet_Change(ByVal Target As Excel.Range)If Target.Cells.Count > 1 Then Exit Sub
Select Case Range(A20).value
Case Is = 0
Run "ShowAdminSheets"
Run "HideUserSheets"
Case Is = 1
Run "HideAdminSheets"
Run "ShowUserSheets"
End Select
End If
End Sub
 
Upvote 0
That doesn't seem to work either. It is still not recognizing it until I double click on it. Also when I double click now it is returning a compile error message.
 
Upvote 0
You can use the Calculate event, which will fire when the sheet calculates. Just note that it doesn't support the target argument.
 
Upvote 0
Can you please give me an idea of what that would look like? I'm sorry I'm new to VB.
 
Upvote 0
Using what was already posted:

Code:
Private Sub Worksheet_Calculate()
  Select Case Range("A20").Value
    Case Is = 0
      Run "ShowAdminSheets"
      Run "HideUserSheets"
    Case Is = 1
      Run "HideAdminSheets"
      Run "ShowUserSheets"
  End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,901
Members
449,097
Latest member
dbomb1414

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