Run VBA when formula changes target cell to hide rows

neilcsmith1984

New Member
Joined
May 25, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have a problem running vba from a target cell that derives from a formula.

I have created the "example book" which shows what I am trying to achieve.

I have 2 dependent combo boxes that update a forecast table on sheet 2. The forecast table will vary in size depending on the combo box selections, eg, one selection may only have 1 row of data whereas another could have 4.

I have the below vba code that hides the rows that are not used in the forecast table based on the value in A1, which derives from a formula, however, when I change the combo boxes the vba doesn't update. It will only update when i actually change the value of A1.

I have tried to use calculate events etc, but I am very new to VBA and I am struggling to find a solution that will run the vba code when the formula updates the value in A1.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then
Rows("8:13").Hidden = False
If Target.Value > 0 And Target.Value < 19 Then
Rows(Target.Value + 8 & ":13").Hidden = True
End If
End If
End Sub

EDIT:
I do not know how to upload my excel sheet
 
Last edited by a moderator:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
thanks for the response
the formula in cell A1 is: =COUNTIFS(FC[PROD],B5,FC[MARKET],BD1)
 
Upvote 0
See if this does what you want:
VBA Code:
Private Sub Worksheet_Calculate()
    Rows("8:13").Hidden = False
    If Range("A1") > 0 And Range("A1") < 19 Then
        Rows(Range("A1").Value + 8 & ":13").Hidden = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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