Call a Macro for Long List of Cells

fgiguere

New Member
Joined
Apr 20, 2009
Messages
4
I'm making a worksheet witch included a popup calendar. So when I select a cell with tab, the arrows or by clicking it, it calls my macro. It's a macro named "OpenCalendar" that I previously made witch works fine.

My 1st question is, how can I call my macro for a long list of cells. Here's what I wrote:

Private Sub (Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Address
Case "$B$5", $B$6", $B$7" '...$B$76
Call OpenCalendar
End Select
End Sub
It works fine but I don't want to enter by "hand" each cells like $B$5, $B$6 etc in my procedure. Is there a quickest way to do that?

My 2nd question is, if in excel, I merged to cells together, is it possible to apply my procedure to the merged cell? And if so, for exemple, if I merged I4 with I5, how do I call this new cell? I4?

Thank you for your help!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hello and welcome to MrExcel.

1.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B5:B76")) Is Nothing Then
    Call OpenCalendar
End If
End Sub

2. Avoid merged cells - they cause havoc with VBA.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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