Problem with Worksheet_Calculate() / Worksheet_Change()

Brett Thompson

New Member
Joined
Oct 5, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello all
Hoping for some help on a simple workbook we would like to put together...
Using a combo box from form control; we would like the 'cell link' value, derived from the value selected in the combo box, to automatically trigger a macro. As a concept, the workbookcurrently has 2 macros, but there would be more when finished.
When I point the VBA at a manually changing cell, the macros run & hide / unhide the columns as excepted, but we can't get it to work from the result of the combo box.
VBA Code:
Sub ReEnableEvents()
    Application.EnableEvents = True
End Sub


Sub Worksheet_Calculate()
    Dim target As Range
    Set target = Range("D2")
    If Not Intersect(target, Range("D2")) Is Nothing Then
    End If
    If target.Value = 1 Then
    Call ShowAll
    End If
    If target.Value = 2 Then
    Call ShowHandS
    End If
End Sub
Hope this makes sense? Thanks for reading & any questions, please ask...

Many thanks
B
 
Last edited by a moderator:

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,129
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Why not assign a macro to the form control directly?
 

Brett Thompson

New Member
Joined
Oct 5, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Thanks Rory.

I'd put that down to a severe lack of knowledge on my part. How would I do that?

Cheers
B
 

Brett Thompson

New Member
Joined
Oct 5, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Sorry, Rory...Just to add. I'm not sure how you assign conditional macros to form control. I can see how a single macro can be assigned...

B
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,129
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

You'd create a macro that has the conditions in it - for example:

VBA Code:
Sub CheckValue()
If Range("D2").Value = 1 Then
Call ShowAll
ElseIf Range("D2").Value = 2 Then
Call ShowHandS
    End If
End Sub
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,129
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Glad to help. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,017
Messages
5,599,362
Members
414,306
Latest member
Dennis_vdw

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
Top