VBA - Including additional Worksheet_Change

Binbs

New Member
Joined
Jan 7, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have the following VBA which will refresh my pivot when cells in the range are updated.

VBA Code:
Sub Worksheet_Change(ByVal Target As Range)

    Dim KeyCells As Range

    Set KeyCells = Range("I7:J7")

    If Not Application.Intersect(KeyCells, Target) Is Nothing Then

        Worksheets("CST View").PivotTables("AutoOL").PivotCache.Refresh
    
End If

End Sub

I want to include another Worksheet_Change shown below. This code is supposed to allow hyperlinks to function in the pivot. I've tested it separately but have been unable combine with the code above.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count <> 1 Then Exit Sub
On Error Resume Next
Application.ActiveWorkbook.FollowHyperlink Address:=CStr(Target.Value), NewWindow:=True
End Sub

Can anyone help me combine these?

Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
They aren't the same procedures.
The one on top is a "Worksheet_Change" event procedure, and the one below is a "Worksheet_SelectionChange".

They work totally differently. The first is fired when cells are manually updated. The second is fired when cells are selected.
Since they are different types of event procedures, they can both co-exist in the same VBA module as-is.
 
Upvote 0
Solution
They aren't the same procedures.
The one on top is a "Worksheet_Change" event procedure, and the one below is a "Worksheet_SelectionChange".

They work totally differently. The first is fired when cells are manually updated. The second is fired when cells are selected.
Since they are different types of event procedures, they can both co-exist in the same VBA module as-is.
Got it, thanks!
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

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