Adding dates within a comment
Hi Jock
I assume your code is in the Worksheet_Change subroutine?
The following does what I understand you need, but this is fixed on cells A1
and B1 for the dates and C1 for the comment. If you need to work with other
cells, this code will have to be modified accordingly
I'm using shorthand notation for the cell addresses - .[a1] is equivalent to
..Range("A1") etc.
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.AddressLocal(RowAbsolute:=False, ColumnAbsolute:=False)
Case "A1"
Rem check that Target contains a recognisable date and that C1 has no
comment. If both true, then add the date (from A1) + 10 days into C1 comment
If (IsDate(Target) And ActiveSheet.[c1].Comment Is Nothing) Then
ActiveSheet.[c1].AddComment.Text Text:=Format(Target + 10, "d mmm yyyy")
Case "B1"
Rem check that Target contains a recognisable date and that C1 does have
a comment. If both true, then add the date (from B1) + 10 days, plus
additional detail into C1 comment
If IsDate(Target) And Not (ActiveSheet.[c1].Comment Is Nothing) Then
ActiveSheet.[c1].Comment.Text Text:=Format(Target + 10, "d mmm yyyy") & "
extra detail"
Case Else
End Select
End Sub
--
Nick
"Jock" wrote:
This first part I can get to work fine:
If a date is entered in A1, a comment will appear in C1 showing the date
(from A1) plus 10 days.
If a date is then entered in B1, the comment in C1 will be amended to the
date from B1 plus 10 days.
What I am struggling with is:
If a date is entered in A1, a comment will appear in C1 showing the date
(from A1) plus 10 days. (same as above)
However, if a date is then entered in B1, the comment in C1 will be amended
to the date from A1 plus 10 days.
partial code below:
Error Resume Next
If Not Intersect(Target, Me.Range("B4:B30")) Is Nothing Then
With Target
If .Value < "" Then
Application.EnableEvents = False
strTemp = Target.Offset(0, 1).Comment.Text
Target.Offset(0, 1).ClearComments
Target.Offset(0, 1).AddComment.Text Text:=strTemp ' & " " & "AoS
filed. Defence now due by: "
On Error GoTo 0
Application.EnableEvents = True
End If
How do I get the code to look at column A rather than the Target column B
and use the date in A?
--
Traa Dy Liooar
Jock
|