Called macro doesn't do anything

Limone

Board Regular
Joined
Dec 20, 2018
Messages
57
Hi.
I'm trying to call a macro using a Worksheet_Change Event but everytime I run it nothing happens. The event itself works great and recognized that the macro doesn't exist after I tried deleting it. I've also tried testing my macro using the Immediate Window feature and everything worked as it was supposed to.

Here are my codes, thanks in advance

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$W$6" Then
        Call MyMacro
    End If
End Sub

Code:
Sub MyMacro()
    If ThisWorkbook.Sheets("Sheet1").Range("Y8") = True Then
        MsgBox "hey"
        Else
        Exit Sub
    End If
End Sub
 
You cant attach files on this forum.
Upload the file to an online storage site and post a link to it, though some people may not download the file for fear of viruses.

That way we can examine and test the data
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
What's the formula in Y8?

W6 = cell containing employee name
=COUNTIF(EmployeeTable[Employees];$W$6)>1

You cant attach files on this forum.
Upload the file to an online storage site and post a link to it, though some people may not download the file for fear of viruses.

That way we can examine and test the data

Here's the file, hope you can figure it out even thought it's in Italian. The sheet containing the codes is "Copertina" (Sheet 2, Module 4).
http://s000.tinyupload.com/index.php?file_id=30445131021308074908

Thanks a lot for your help.
 
Upvote 0
This is a "Worksheet Change" macro with a target address of W6.
Am no VBA expert, far from it, but doesnt that mean unless you have selected cell W6 in the Copertina sheet and attempted to amend the value the macro wont run?

If I select Copertina!W6, press F2 and press return I get the message "hey" so it does run.
 
Upvote 0
Ooops, you're right! This is the mistake I make everytime. Sorry everyone for the bother. Thank you very much! :laugh:
 
Upvote 0
Limone, in order to step through code, in the Visual Basic window of the macro, you can press F8, and press it for each line of code. Another method, if VB isn't open is to go to View --> Macros --> View Macros; select the macro then click Step into button.

The highlighted line of code is the one about to be executed - you can hover the cursor over any variable to see the current value - this is extremely helpful in debugging.

FYI - first instance of a computer bug: http://www.computerhistory.org/tdih/september/9/
 
Upvote 0
Just to point out that you need to put a breakpoint in Event code to be able to step through it using F8 as it needs to be triggered first
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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