Target.Address to specific Worksheet

GreenyMcDuff

Active Member
Joined
Sep 20, 2010
Messages
313
Hi all,

This seems like a really easy question but I can't find an answer on google :(

I am using this code

Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$H$2" Then
        Run
        MsgBox ("Report Compiled Successfully")
    End If
End Sub

To start my macro when someone clicks on Cell H2.

This code has to be maintained in a module and so I now need the macro to run when Cell H2 is click in the Worksheet "Data" only.

I figured using this would work:

Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "[COLOR=red]Data![/COLOR]$H$2" Then
        Run
        MsgBox ("Report Compiled Successfully")
    End If
End Sub

But it does not,

Thanks for all your help :D

Chris
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If you put that code in Data's code module (right click Data tab, View Code) it will only rin when H2 is selected in the Data sheet.
 
Upvote 0
Thanks for your reply Peter.

Unfortunately, I can't do that because I can't have any code in the sheet when the macro has finished.

The Macro copies all the worksheets into a new workbook, and unfortunately if this code is attached to the "Data" sheet it will get copied across as well.

Don't suppose you have any other thoughts???
 
Upvote 0
Try in the ThisWorkbook module

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name <> "Data" Then Exit Sub
'
'rest of code
'
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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