Control Comments (or a hover over function) with Another Cell

bstboy

Board Regular
Joined
Oct 4, 2005
Messages
83
Hello

How do I control the comments of a particular cell (let's just say Sheet 2, cell A1) with the data that is in another cell (say Sheet 1, cell B3). So when the user hovers over or looks at the comments of Sheet 2 Cell A1, they see what is contained in Sheet 1 cell B3.

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
There are a couple of ways that one could do this.
All of them involve VBA.

What is in the cell receiving the comment adjustments (Sheet2!A1)? A formula or a user entered value?

Similarly, what is in the sending cell, formula or user entry?
 
Upvote 0
There are a couple of ways that one could do this.
All of them involve VBA.

What is in the cell receiving the comment adjustments (Sheet2!A1)? A formula or a user entered value?

Similarly, what is in the sending cell, formula or user entry?

Both are hardcoded values (user entry)
 
Upvote 0
You could put this in Sheet1's code module

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("B3")) Is Nothing Then
        On Error GoTo makeComment
        ThisWorkbook.Sheets("Sheet2").Range("A1").Comment.Text Text:=CStr(Range("B3").Value)
        On Error GoTo 0
    End If
    Exit Sub
makeComment:
    Err.Clear
    On Error Resume Next
    With ThisWorkbook.Sheets("Sheet2").Range("A1")
        .AddComment
    End With
    On Error GoTo DoubleError
    Resume
DoubleError:
    
End Sub
 
Upvote 0
You could put this in Sheet1's code module

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("B3")) Is Nothing Then
        On Error GoTo makeComment
        ThisWorkbook.Sheets("Sheet2").Range("A1").Comment.Text Text:=CStr(Range("B3").Value)
        On Error GoTo 0
    End If
    Exit Sub
makeComment:
    Err.Clear
    On Error Resume Next
    With ThisWorkbook.Sheets("Sheet2").Range("A1")
        .AddComment
    End With
    On Error GoTo DoubleError
    Resume
DoubleError:
    
End Sub

Thanks so much. So if I wanted to do this with multiple cells, would I add some kind of AND function to this? Sorry but I have very little experience with VBA.
 
Upvote 0
Here's one approach
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cellsShowingComments As Range
    Dim PrecedentsForComments As Range
    Dim oneCell As Range
    
    Set cellsShowingComments = ThisWorkbook.Sheets("Sheet2").Range("A1,A3,A4")
    Set PrecedentsForComments = Range("B3:D4")
    If Not Application.Intersect(Target, PrecedentsForComments) Is Nothing Then
        For Each oneCell In cellsShowingComments
            With oneCell
                On Error GoTo makeComment
                Select Case .Address
                    Case "$A$1": .Comment.Text Text:=CStr(Range("B3")) & "-" & CStr(Range("B4"))
                    Case "$A$3": .Comment.Text Text:=CStr(Range("C3")) & " of " & CStr(Range("C4"))
                    Case "$A$4": .Comment.Text Text:=CStr(Val(CStr(Range("D3"))) + Val(CStr(Range("D4"))))
                End Select
            End With
        Next oneCell
        On Error GoTo 0
    End If
    Exit Sub
    
makeComment:
    Err.Clear
    On Error Resume Next
    With oneCell
        .AddComment
    End With
    On Error GoTo DoubleError
    Resume
DoubleError:
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,530
Members
444,794
Latest member
HSAL

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