Triggering Macro

Yogi

Board Regular
Joined
Oct 21, 2002
Messages
74
I have a Macro in cell B2. How do I trigger this Macro by clicking cell B2?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

B_2

Board Regular
Joined
Aug 24, 2002
Messages
210
Modify this to suit your needs...


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Set vrange = Range("A1")


For Each cell In Target
If Union(cell, vrange).Address = vrange.Address Then
If Range("A1") = "1" Then
Range("A6") = "H"
Range("A7") = "E"
Range("A8") = "L"
Range("A9") = "P"
End If


If Range("A1") = "2" Then
Range("A6") = "G"
Range("A7") = "O"
Range("A8") = "O"
Range("A9") = "D"
End If
End If
Next cell

End Sub
 

Yogi

Board Regular
Joined
Oct 21, 2002
Messages
74
My Macro in B2 is a Countdown Macro. Only Cell B2 is affected. How would this formula be modified if the macro is only for one cell.
Thanks
 

zacemmel

Well-known Member
Joined
Apr 29, 2002
Messages
636
I think this is more of what you are looking for:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$B$2" Then
'ur code here
End If

End Sub

Questions?

http://www.excelquestions.com
This message was edited by zacemmel on 2002-10-26 14:23
 

Yogi

Board Regular
Joined
Oct 21, 2002
Messages
74
I entered the following:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$B$2" Then
Sub CountDown()
Dim pausetime As Single
Dim start As Single
Dim finish As Single
Dim totaltime As Single

pausetime = 25 ' Set duration.
start = Timer ' Set start time.
Sheets(1).Range("B2").Value = 25
Do While Timer < start + pausetime
DoEvents ' Yield to other processes.
Sheets(1).Range("B2").Value = _
Format(pausetime + (start - Timer), "##")
Loop

Sheets(1).Range("B2").Value = 25

End If

End Sub

With no success. Please Advise
 

Forum statistics

Threads
1,143,613
Messages
5,719,713
Members
422,242
Latest member
hishamkhatri

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
Top