Automatically run macro when cell value changes

Rob161

New Member
Joined
Mar 2, 2015
Messages
3
Hi,

With regarding the following macro, I need help adding the extra coding required if I wish to have the macro run automatically when the value of a particular cell changes. I'm new to using <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> and am always getting errors when I attempt this.

Thanks in advance
Rob


With theComment
.Visible = False
.Text Text:="My comment" & Chr(10) & ""
With .Shape
.Fill.Transparency = 0#
.Line.Weight = 0.75
.Line.DashStyle = msoLineSolid
.Line.Style = msoLineSingle
.Line.Transparency = 0#
.Line.Visible = msoTrue
.Line.ForeColor.RGB = RGB(0, 0, 0)
.Line.BackColor.RGB = RGB(255, 255, 255)
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.BackColor.SchemeColor = 80
On Error Resume Next
.Fill.UserPicture MyPath
If Not Err.Number = 0 Then
MsgBox "You do not have a valid path to the picture file" & Chr(13) & _
"Please try again.", vbOKOnly, "Notification"

theComment.Delete 'remove the incomplete, pictureless comment ??
End If
On Error GoTo 0
End With
End With


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Rob161,

Assuming your original code is still Sub 'Add_Comment' and that the 'particular cell' is e.g. B2 then add the below to the sheet's code module.........

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Cells.Count > 1 Then Exit Sub
'Assumes cell B2 is the 'Particular cell'  edit to suit *******
If Intersect(Target, Range("B2")) Is Nothing Then Exit Sub '******
Application.EnableEvents = False
Application.ScreenUpdating = False


Call Add_Comment  'Original add_comment sub


Application.EnableEvents = True
Application.ScreenUpdating = True


End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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