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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Instead of exiting from the MyMacro sub place another MsgBox in there after the Else
So you get some form of output regardless.

If you get a Hey then Sheet1!Y8=TRUE
If you get some other form of output then Sheet1!Y8 does not = TRUE
If you get no output then MyMacro is not being called.
 
Last edited:
Upvote 0
Hello and welcome.

have you stepped through the change event and followed what happens? Does the 'Call MyMacro' line actually execute? If so does it then jump the correct sub?
 
Upvote 0
I just commented out everything bar the msgbox in the regular sub and the worksheet_change called it fine.
So the only things that I can think of is that this statement isn't true
Code:
If ThisWorkbook.Sheets("Sheet1").Range("Y8") = True
or
You haven't put the regular sub in a regular module i.e. you have put the code in either the sheet module or the ThisWorkbook module. It must be in a regular module.
 
Upvote 0
Out of curiosity what value is actually in Sheets("Sheet1").Range("Y8")?
 
Upvote 0
Instead of exiting from the MyMacro sub place another MsgBox in there after the Else
So you get some form of output regardless.

If you get a Hey then Sheet1!Y8=TRUE
If you get some other form of output then Sheet1!Y8 does not = TRUE
If you get no output then MyMacro is not being called.

Thanks for the suggestion. I get no input unfortunately.

Hello and welcome.

have you stepped through the change event and followed what happens? Does the 'Call MyMacro' line actually execute? If so does it then jump the correct sub?

I don't know how to do that unfortunately. I've changed my worksheet_change event code so that a message would pop up when the cell is changed and nothing happened, so I guess the problem might rely there?

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

I just commented out everything bar the msgbox in the regular sub and the worksheet_change called it fine.
So the only things that I can think of is that this statement isn't trueCode:
If ThisWorkbook.Sheets("Sheet1").Range("Y8") = True

or
You haven't put the regular sub in a regular module i.e. you have put the code in either the sheet module or the ThisWorkbook module. It must be in a regular module.

The statement is true. As I said, I tested it using the Immediate Window function and it worked.
I've saved the event as a Microsoft Excel Object and the macro as a module.

Out of curiosity what value is actually in Sheets("Sheet1").Range("Y8")?

A COUNTIF formula that returns either TRUE or FALSE and I want the message to pop up in case it returns TRUE.
 
Upvote 0
Try
Code:
If ThisWorkbook.Sheets("Sheet1").Range("Y8") = "TRUE"
 
Last edited:
Upvote 0
Sorry for the awful formatting, I've never really been on a forum before and I don't have time now to get the hang of it :(
 
Upvote 0
Try
Code:
If ThisWorkbook.Sheets("Sheet1").Range("Y8") = "TRUE"

Tried your suggestion, using both English and my native language, and it didn't work. I guess the problem might be about the event not firing (even though excel does warn me when something's wrong with the code) but I'm not sure how I can test it.
 
Upvote 0

Forum statistics

Threads
1,216,071
Messages
6,128,622
Members
449,460
Latest member
jgharbawi

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