Error when I run vba code after typing in a cell

KlausW

Active Member
Joined
Sep 9, 2020
Messages
458
Office Version
  1. 2016
Platform
  1. Windows
Hi every one
I use this VBA code to insert a letter into a cell and then have it run a VBA code afterwards.
But I can't get it to run can anyone help.
Any help will be appreciated.
Best regards
Klaus W


VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Selection.Count = 1 Then

If Not Intersect(Target, Range("k2:k154")) Is Nothing Then

Range("y16").Value = Target.Offset(0, -10).Value

Call Send_mail

Target.Value = "S"

End If

If Not Intersect(Target, Range("l2:l154")) Is Nothing Then

Range("aa16").Value = Target.Offset(0, -11).Value

Call Send_mail1

Target.Value = "G"

End If

End If

End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
@KlausW On the face of it the code looks fine to me.
Maybe a silly question but you do have this code in the code module of the sheet concerned?
It will not work if in a Code Module.

Or, do you have events accidentally disabled?
Maybe type the command line
VBA Code:
Application.EnableEvents = True
in the Immediate pane of the VBA editor and hit return.
 
Last edited:
Upvote 0
@KlausW On the face of it the code looks fine to me.
Maybe a silly question but you do have this code in the code module of the sheet concerned?
It will not work if in a Code Module.

Or, do you have events accidentally disabled?
Maybe type the command line
VBA Code:
Application.EnableEvents = True
in the Immediate pane of the VBA editor and hit return.
module of the sheet
 
Upvote 0
@KlausW On the face of it the code looks fine to me.
Maybe a silly question but you do have this code in the code module of the sheet concerned?
It will not work if in a Code Module.

Or, do you have events accidentally disabled?
Maybe type the command line
VBA Code:
Application.EnableEvents = True
in the Immediate pane of the VBA editor and hit return.
@KlausW On the face of it the code looks fine to me.
Maybe a silly question but you do have this code in the code module of the sheet concerned?
It will not work if in a Code Module.

Or, do you have events accidentally disabled?
Maybe type the command line
VBA Code:
Application.EnableEvents = True
in the Immediate pane of the VBA editor and hit return.
I just can't figure out where to put it
 
Upvote 0
this is error message
 

Attachments

  • Pic01.png
    Pic01.png
    36.3 KB · Views: 10
Upvote 0
I'm not really sure!
but is that in standard module 1 or rename module 1?
is name in standard module 1 like this ?
Sub Send_mail()
End Sub
if it's so , can you change the name and see how goes?
 
Upvote 0
Solution
Yep, looks like you have a code module that you have named Send_mail ??
With your subroutine within it also named Send_mail ??

Rename that Module so that it does not conflict with the Sub name.

HTH
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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