PC Review


Reply
Thread Tools Rate Thread

adding comment to cell if value changed

 
 
tpeter
Guest
Posts: n/a
 
      12th Nov 2009
I have found the following code online and it adds a comment to a cell if
someone changes it. It works fine in the free download and if I paste the
code into a blank workbook. But when I put it into a specific worksheet I
have the code breaks on the format date function. Any help would be great.

Option Explicit
Public preValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
Target.ClearComments
Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
& "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
Environ("UserName")
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
If Target = "" Then
preValue = "a blank"
Else: preValue = Target.Value
End If
End Sub

Tim Peter
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      12th Nov 2009
Hi,

There's nothing wring with the code, are you sure your not suffering from an
unfortunate line-wrap. The following bit of the code goes all in a single line

Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
& "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
Environ("UserName")


or you can use continuation like this and break it in 3 lines

Target.AddComment.Text Text:="Previous Value was " & _
preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & _
Chr(10) & "By " & Environ("UserName")

Mike

"tpeter" wrote:

> I have found the following code online and it adds a comment to a cell if
> someone changes it. It works fine in the free download and if I paste the
> code into a blank workbook. But when I put it into a specific worksheet I
> have the code breaks on the format date function. Any help would be great.
>
> Option Explicit
> Public preValue As Variant
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Target.Count > 1 Then Exit Sub
> If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> Target.ClearComments
> Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> Environ("UserName")
> End Sub
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> If Target.Count > 1 Then Exit Sub
> If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> If Target = "" Then
> preValue = "a blank"
> Else: preValue = Target.Value
> End If
> End Sub
>
> Tim Peter

 
Reply With Quote
 
tpeter
Guest
Posts: n/a
 
      12th Nov 2009
Thanks for answering Mike,

That is the part I can't figure out. It works in blank workbooks but when I
put it into a current workbook I have created it breaks on format and says
"expected variable or procedure, not modual". If I take out the Format then
it works but I have no date when the cell was changed. Thanks again for your
help.

Tim Peter

"Mike H" wrote:

> Hi,
>
> There's nothing wring with the code, are you sure your not suffering from an
> unfortunate line-wrap. The following bit of the code goes all in a single line
>
> Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> Environ("UserName")
>
>
> or you can use continuation like this and break it in 3 lines
>
> Target.AddComment.Text Text:="Previous Value was " & _
> preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & _
> Chr(10) & "By " & Environ("UserName")
>
> Mike
>
> "tpeter" wrote:
>
> > I have found the following code online and it adds a comment to a cell if
> > someone changes it. It works fine in the free download and if I paste the
> > code into a blank workbook. But when I put it into a specific worksheet I
> > have the code breaks on the format date function. Any help would be great.
> >
> > Option Explicit
> > Public preValue As Variant
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > If Target.Count > 1 Then Exit Sub
> > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> > Target.ClearComments
> > Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> > & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> > Environ("UserName")
> > End Sub
> >
> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > If Target.Count > 1 Then Exit Sub
> > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> > If Target = "" Then
> > preValue = "a blank"
> > Else: preValue = Target.Value
> > End If
> > End Sub
> >
> > Tim Peter

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      12th Nov 2009

Have you named your module the same as the code

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"tpeter" <(E-Mail Removed)> wrote in message
news:EBDC7329-1CC7-4E99-8463-(E-Mail Removed)...
> Thanks for answering Mike,
>
> That is the part I can't figure out. It works in blank workbooks but when
> I
> put it into a current workbook I have created it breaks on format and says
> "expected variable or procedure, not modual". If I take out the Format
> then
> it works but I have no date when the cell was changed. Thanks again for
> your
> help.
>
> Tim Peter
>
> "Mike H" wrote:
>
>> Hi,
>>
>> There's nothing wring with the code, are you sure your not suffering from
>> an
>> unfortunate line-wrap. The following bit of the code goes all in a single
>> line
>>
>> Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
>> & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
>> Environ("UserName")
>>
>>
>> or you can use continuation like this and break it in 3 lines
>>
>> Target.AddComment.Text Text:="Previous Value was " & _
>> preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & _
>> Chr(10) & "By " & Environ("UserName")
>>
>> Mike
>>
>> "tpeter" wrote:
>>
>> > I have found the following code online and it adds a comment to a cell
>> > if
>> > someone changes it. It works fine in the free download and if I paste
>> > the
>> > code into a blank workbook. But when I put it into a specific worksheet
>> > I
>> > have the code breaks on the format date function. Any help would be
>> > great.
>> >
>> > Option Explicit
>> > Public preValue As Variant
>> > Private Sub Worksheet_Change(ByVal Target As Range)
>> > If Target.Count > 1 Then Exit Sub
>> > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
>> > Target.ClearComments
>> > Target.AddComment.Text Text:="Previous Value was " & preValue &
>> > Chr(10)
>> > & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
>> > Environ("UserName")
>> > End Sub
>> >
>> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>> > If Target.Count > 1 Then Exit Sub
>> > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
>> > If Target = "" Then
>> > preValue = "a blank"
>> > Else: preValue = Target.Value
>> > End If
>> > End Sub
>> >
>> > Tim Peter


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      12th Nov 2009
Just to add to Don's idea...

Check to see if you created your own function/sub named Format.

tpeter wrote:
>
> Thanks for answering Mike,
>
> That is the part I can't figure out. It works in blank workbooks but when I
> put it into a current workbook I have created it breaks on format and says
> "expected variable or procedure, not modual". If I take out the Format then
> it works but I have no date when the cell was changed. Thanks again for your
> help.
>
> Tim Peter
>
> "Mike H" wrote:
>
> > Hi,
> >
> > There's nothing wring with the code, are you sure your not suffering from an
> > unfortunate line-wrap. The following bit of the code goes all in a single line
> >
> > Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> > & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> > Environ("UserName")
> >
> >
> > or you can use continuation like this and break it in 3 lines
> >
> > Target.AddComment.Text Text:="Previous Value was " & _
> > preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & _
> > Chr(10) & "By " & Environ("UserName")
> >
> > Mike
> >
> > "tpeter" wrote:
> >
> > > I have found the following code online and it adds a comment to a cell if
> > > someone changes it. It works fine in the free download and if I paste the
> > > code into a blank workbook. But when I put it into a specific worksheet I
> > > have the code breaks on the format date function. Any help would be great.
> > >
> > > Option Explicit
> > > Public preValue As Variant
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > If Target.Count > 1 Then Exit Sub
> > > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> > > Target.ClearComments
> > > Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> > > & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> > > Environ("UserName")
> > > End Sub
> > >
> > > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > > If Target.Count > 1 Then Exit Sub
> > > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> > > If Target = "" Then
> > > preValue = "a blank"
> > > Else: preValue = Target.Value
> > > End If
> > > End Sub
> > >
> > > Tim Peter


--

Dave Peterson
 
Reply With Quote
 
tpeter
Guest
Posts: n/a
 
      13th Nov 2009
That was it. I had a different modual nameded format. Thank all of you for
your excellent troubleshooting skills. I greatly appreciate it.

Tim Peter

"Dave Peterson" wrote:

> Just to add to Don's idea...
>
> Check to see if you created your own function/sub named Format.
>
> tpeter wrote:
> >
> > Thanks for answering Mike,
> >
> > That is the part I can't figure out. It works in blank workbooks but when I
> > put it into a current workbook I have created it breaks on format and says
> > "expected variable or procedure, not modual". If I take out the Format then
> > it works but I have no date when the cell was changed. Thanks again for your
> > help.
> >
> > Tim Peter
> >
> > "Mike H" wrote:
> >
> > > Hi,
> > >
> > > There's nothing wring with the code, are you sure your not suffering from an
> > > unfortunate line-wrap. The following bit of the code goes all in a single line
> > >
> > > Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> > > & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> > > Environ("UserName")
> > >
> > >
> > > or you can use continuation like this and break it in 3 lines
> > >
> > > Target.AddComment.Text Text:="Previous Value was " & _
> > > preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & _
> > > Chr(10) & "By " & Environ("UserName")
> > >
> > > Mike
> > >
> > > "tpeter" wrote:
> > >
> > > > I have found the following code online and it adds a comment to a cell if
> > > > someone changes it. It works fine in the free download and if I paste the
> > > > code into a blank workbook. But when I put it into a specific worksheet I
> > > > have the code breaks on the format date function. Any help would be great.
> > > >
> > > > Option Explicit
> > > > Public preValue As Variant
> > > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > > If Target.Count > 1 Then Exit Sub
> > > > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> > > > Target.ClearComments
> > > > Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10)
> > > > & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " &
> > > > Environ("UserName")
> > > > End Sub
> > > >
> > > > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > > > If Target.Count > 1 Then Exit Sub
> > > > If Intersect(Target, Range("$C$15:$j$15")) Is Nothing Then Exit Sub
> > > > If Target = "" Then
> > > > preValue = "a blank"
> > > > Else: preValue = Target.Value
> > > > End If
> > > > End Sub
> > > >
> > > > Tim Peter

>
> --
>
> Dave Peterson
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Comment in a cell be changed as the content in another cell ?? =?Utf-8?B?QW1pdCBLdW1hciBCYWlkeWFrYQ==?= Microsoft Excel Misc 3 10th Jan 2007 03:35 AM
Adding a comment to a cell in VBA?! =?Utf-8?B?TWF1cnkgTWFya293aXR6?= Microsoft Excel Programming 8 27th Oct 2005 04:15 PM
Event on changed comment for a cell MattiasP Microsoft Excel Discussion 2 13th Jul 2005 03:17 PM
Cell comment boxes shouldn't change size/shape unless changed by u =?Utf-8?B?c2Ft?= Microsoft Excel Misc 1 3rd Mar 2005 05:23 PM
Adding a comment to a cell. adn4n Microsoft Excel Misc 4 23rd Apr 2004 02:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:33 AM.