Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

Excel VBA

Hello again.  I was needing to find out.  How do i go about setting up a macro that will run, whenever the one of the  cells are selected on sheets "data" cell z1 or z2 or z3 or z4 or z5 or z6.  Thanks
0
sandramac
Asked:
sandramac
  • 2
1 Solution
 
bruintjeCommented:
Hi sandramac,

this is for office questions
http://www.experts-exchange.com/jsp/qList.jsp?ta=msoffice

for your question

-bring up the VB Editor
-look in the project explorer for the sheet called Sheetx(Data)
-double click on it which will bring up the code window
-then place this code in the code window

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Rem declare vars
Dim i As Integer
i = 1
 Rem select case to look for the address of current clicked cell
 While Not i > 6
   If InStr(1, Target.Address, "$Z$", vbBinaryCompare) Then
     If Target.Address = "$Z$" & i Then
       Rem selected cell in range so show message
       MsgBox "Cell within Range selected"
       Rem run your macro here
     End If
   Else
     Rem cell is not in column so exit early
     Exit Sub
   End If
   i = i + 1
 Wend
End Sub

HTH:O)Bruintje
0
 
bruintjeCommented:
instead of the messagebox you can place your macro to run in there like

If Target.Address = "$Z$" & i Then
   call macro1  
End If
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now