Excel Run Macro When A Specific Cell Selected

Trigger Macro Or VBA Code When A Specific Cell Is Selected

         In this Excel template, the background color of the cells was painted different colors with  macros.

         When cells of specific range in "Example" worksheet  (between AR4 and AR28 cells) are selected,the macros are triggered .For this purpose, we have added the following codes to the page's Worksheet_SelectionChange method :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Address
Case "$AR$4": Call col_one
Case "$AR$5": Call col_two
Case "$AR$6": Call col_three
Case "$AR$7": Call col_four
Case "$AR$8": Call col_five
Case "$AR$9": Call col_six
Case "$AR$10": Call col_seven
Case "$AR$11": Call col_eight
Case "$AR$12": Call col_nine
Case "$AR$13": Call col_ten
Case "$AR$14": Call col_eleven
Case "$AR$15": Call col_twelve
Case "$AR$16": Call col_thirteen
Case "$AR$17": Call col_fourteen
Case "$AR$18": Call col_fifteen
Case "$AR$19": Call col_sixteen
Case "$AR$20": Call col_seventeen
Case "$AR$21": Call col_eighteen
Case "$AR$22": Call col_nineteen
Case "$AR$23": Call col_twenty
Case "$AR$24": Call col_twentyone
Case "$AR$25": Call col_twentytwo
Case "$AR$26": Call col_twentythree
Case "$AR$27": Call col_twentyfour
Case "$AR$28": Call col_twentyfive
End Select
End Sub

The Call statement was used to call a Sub procedure.  

excel run macro when selected cell

We added sub procedures (macros) to the module.

excel vba procedures

No comments:

Post a Comment