VBA - adjust Worksheet Change to work across different sheets

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
I have this worksheet change below that works well. I'd like to amend it so it works across worksheets if possible. I'm just not sure how to do this or where to place this in the project(I'm guessing in This Workbook???). I obviously need to add the different worksheet names to each of the ranges so not certain I know how to do that properly either.

Any help would be fantastic - I'm a bit new to VBA.

VBA Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
If Target.Address = Range("c12:c46").Address Then
Range("$j$2").Value = "Please Select..."

End If

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
How about
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
   If Not Intersect(Target, Sh.Range("C12:C46")) Is Nothing Then
      Sh.Range("J2").Value = "Please Select..."
   End If
End Sub
This needs to go in the ThisWorkbook module.
 
Upvote 0
The two ranges are in different sheets, but they're not referenced at all. I'm having a go but have very little idea what I'm doing! C12:C46 is in SheetA and J2 is in SheetB.
 
Upvote 0
Ok, I misunderstood. I thought you wanted the change event to work on multiple sheets.
Use this instead
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Target, Range("C12:C46")) Is Nothing Then
      Sheets("SheetB").Range("J2").Value = "Please Select..."
   End If
End Sub
This needs to go in SheetA code module.
 
Upvote 0
Solution
Thanks Fluff, that's exactly what's needed. If I've already got another sub in this SheetA code module (same first line), what do I need to do to add this one and make it work?

Sorry for all the questions - I'm learning plenty here!
 
Upvote 0
What is the existing code?
 
Upvote 0
Woohoo, I managed to combine them. I'd missed an end if. Does this compilation look correct? Really appreciate the feedback. SheetA and SheetB are renamed now...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("$g$6").Address Then
Range("f14:f17,f21:f24").Value = "Please Select..."

End If

If Not Intersect(Target, Range("C12:C46")) Is Nothing Then
Sheets("Student Folio").Range("J2").Value = "Please Select..."

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,830
Members
449,190
Latest member
rscraig11

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