Select Case Target.Address for range of cells

rjvow

New Member
Joined
Feb 8, 2016
Messages
2
Hi

I have a working code to make a calendar pop up when ever someone selects a specific cell. However I would like to make it work for whenever a cell in a range is selected ("G2:G3000 "I2:I3000" "J2:J3000 "L2:L3000") or anywhere in column G, I, J, and L.

The code I have at the moment will only work for cell L2

It reads:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Address
Case "$L$2"
Call OpenCalendar
End Select
End Sub

Any help would be much appreciated.

Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi there,

You list partial columns that are all in the whole columns you list?

Presuming you want the whole columns, try:

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>  <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_SelectionChange(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>  <SPAN style="color:#00007F">If</SPAN> Selection.Count = 1 <SPAN style="color:#00007F">Then</SPAN><br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Application.Intersect(Me.Range("G:G,I:I,J:J,L:L"), Target) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>      MsgBox "OpenCalendar"<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Mark
 
Upvote 0
try application.intersect for your named range and target address. Create a range and use the UNION function to make it go across multiple ranges

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange as range


set MyRange = union range(("G2:G3000"), Range ("I2:I3000"), range("J2:J3000"), range(L2:L3000")  'and any other areas you want.

If Not Application.Intersect(Target , myRange) Is Nothing Then Call OpenCalendar

 End Sub
 
Last edited:
Upvote 0
Hi there,

You list partial columns that are all in the whole columns you list?

Presuming you want the whole columns, try:

Option Explicit
**
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
**If Selection.Count = 1 Then
****If Not Application.Intersect(Me.Range("G:G,I:I,J:J,L:L"), Target) Is Nothing Then
******MsgBox "OpenCalendar"
****End If
**End If
End Sub


Hope that helps,

Mark

works perfectly thanks!
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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