dynamic comments based on different sheet values

RedOctoberKnight

Board Regular
Joined
Nov 16, 2015
Messages
150
Office Version
  1. 2016
Platform
  1. Windows
Good Morning,

I have a workbook with about 50 or so sheets that contain employee schedules for that day. I'm trying to create a dynamic message VBA where when someone selects the employees name on any of those sheets, it finds and and shows the information that is stored on one sheet (say it's named "employees"). For example, if I select on John Smith, it would pull up a comment box that would contain info like their employee number, Hire date, and Birthday.

I was able to find a code online and piece it together using a dummy workbook to fit my needs but it works when all the data is on the same sheet. I'm unsure how to call that information from the "employees" sheet so i dont have to put all this information on every sheet.

VBA Code:
Option Explicit

Sub CreateDynamicComment()
Dim SelRow As Long
Dim CommText As String
With ActiveSheet
        SelRow = .Range("B4").Value 'Selected Row
        CommText = .Range("D" & SelRow).Value & "   e" & .Range("C" & SelRow).Value & vbCrLf & _
            " " & vbCrLf & _
            "Phone: " & Application.WorksheetFunction.Text(.Range("E" & SelRow).Value, "(###) ###-####") & vbCrLf & _
            " " & vbCrLf & _
            "Job Date: " & .Range("F" & SelRow).Value & vbCrLf & _
            "Hire Date: " & .Range("G" & SelRow).Value & vbCrLf & _
            "Birthday: " & .Range("H" & SelRow).Value & vbCrLf & _
            " " & vbCrLf & _
            "Sun: " & .Range("I" & SelRow).Value & vbCrLf & _
            "Mon: " & .Range("J" & SelRow).Value & vbCrLf & _
            "Tue: " & .Range("K" & SelRow).Value & vbCrLf & _
            "Wed: " & .Range("L" & SelRow).Value & vbCrLf & _
            "Thu: " & .Range("M" & SelRow).Value & vbCrLf & _
            "Fri: " & .Range("N" & SelRow).Value & vbCrLf & _
            "Sat: " & .Range("O" & SelRow).Value
            .Range("D" & SelRow).ClearComments
            .Range("D" & SelRow).AddComment
        With .Range("D" & SelRow).Comment
            .Text Text:=CommText
            .Shape.Width = 210
            .Shape.Height = 230
            .Shape.AutoShapeType = msoShapeRectangle
           .Shape.Fill.ForeColor.RGB = RGB(225, 245, 254)
            .Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
            .Shape.TextFrame.Characters.Font.Name = "arial black"
            .Shape.TextFrame.Characters.Font.Bold = False
            .Shape.TextFrame.Characters.Font.Size = 10
            .Shape.TextFrame.Characters.Font.ColorIndex = 1
            .Shape.Fill.Visible = msoTrue
            .Visible = True
        End With
End With
End Sub

Any help would be much appreciated! Thanks!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,951
Messages
6,122,446
Members
449,083
Latest member
Ava19

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