hyperlink

LadyHarper

New Member
Joined
Jun 28, 2017
Messages
48
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with over 2000 comments in it. I have used VBA coding to create a new sheet that has all the comments on it. I now want to make it so when I click on a cell in the main spreadsheet that has a comment in it, it takes me to the matching cell number listed in the column that states all the cell's with comments in them.
 
I'm terribly sorry about the trouble... I promise I test my code before I reply, so I'm not sure why it's not working anymore.
I think I fixed it. Once again, I apologize. Where it says [Main Sheet Name], put in the name of your main sheet.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Worksheets("Sheet1").Activate
    If Worksheets("Sheet1").Range("D2:D2886").Find(Target) Is Nothing Or IsEmpty(Target) = True Then
        On Error Resume Next
        Worksheets("[Main Sheet Name]").Activate
    Else
        On Error Resume Next
        Worksheets("Sheet1").Cells(Application.WorksheetFunction.Match(Target, Worksheets("Sheet1").Range("D2:D2886"), 0) + 1, 4).Select
                                                                                              'The +1 to account for a header
    End If
End Sub
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
:( I am not sure what I am doing wrong. When I click in cell E15 that has a comment in it, it brings up Sheet1 but is not going to E15 in the B column. I correct the VBA where you have D to B... Still not working
 
Last edited:
Upvote 0
Try this:

In each sheet which needs click functionality (Main, Secondary, Other, etc), paste following code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    SearchCommentCell Target
End Sub

Create a new module in your VBA window (Insert -> Module) and paste following code in it:
Code:
Public Sub SearchCommentCell(Target As Range)
    Dim srchSht As Worksheet
    Dim srchRng As Range, foundCell As Range
    Dim firstAddress As String
    
    'Sheet to search
    Set srchSht = ThisWorkbook.Sheets("Sheet1")
    'Range to search
    Set srchRng = srchSht.Range("B:B")
    'Find the cell - assuming addresses are written as A5 and not A$5$ in Sheet1
    Set foundCell = srchRng.Find(What:=Replace(Target.Address, "$", ""))
    If foundCell Is Nothing Then
        ' not found
    Else
        ' cell found
        ' note down the address of first cell found
        firstAddress = foundCell.Address
        Do
            ' check if the sheet name matches, ie, is this comment for Main!A5 or Secondary!A5
            If (foundCell.Offset(0, -1).Value = ActiveSheet.Name) Then
                ' sheet name matched; activate found cell
                ThisWorkbook.Sheets("Sheet1").Activate
                foundCell.Select
                Exit Do
            End If
            ' else search for next cell with the address
            Set foundCell = srchRng.FindNext(After:=foundCell)
        ' loop until search wraps around
        Loop Until foundCell.Address = firstAddress
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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