RedOctoberKnight
Board Regular
- Joined
- Nov 16, 2015
- Messages
- 152
- Office Version
- 2016
- Platform
- 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.
Any help would be much appreciated! Thanks!
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!