• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Have input box pop up that would then transfer content to cell comment

jski21

New Member
Trying to get an input box to pop up so a user can enter a brief description that will then appear in a comment attached to the cell. The problem I believe I’m running into is the user inputs data into a table on one sheet (DataX) which feeds results over to another sheet (SheetX). It is the results in SheetX’s non-contiguous range where I’d like the comments to reside.

The cells on DataX are matched up to a cell to SheetX by a reference formula. For example, Cell D11 on DataX calculates the value. Cell B26 on SheetX references Cell D11 on DataX by using ='Data X'!D11.

The value test occurs through conditional formatting on SheetX using =AND(A1>0,A1<=0.989). If the value test is met the cell is highlighted red.

This is not really a 1:1 cell reference relationship ('Sheet'X!A1 references 'DataX'!A1) which may be the issue. It does work when it is a 1:1 cell reference relationship. For example, if ‘Sheet’!XB26 references ‘Data’!XB26 the input box pops up and the comment is created.

Also, might it be best to simply have the value test occur on DataX, create an input box to insert a comment there, and then perhaps have the designated cells in SheetX pull the comment in if applicable?





Code:
'This sub is located in the Sheet "Data X" code module.

Private Sub Worksheet_Change(ByVal Target As Range)

'`````````````````````````````````````````````````````'

'Create pop up input box and add comment if"<=98.9%" result'

  Dim sReason As String

  Dim WS As Worksheet

  Dim C As Comment

  Dim rng As Range

 

  If Not Intersect(Target, Me.Range("$B$26:$B$28,$B$30:$B$32,$B$34:$B$36,$B$38:$B$40,$E$26:$E$28,$E$30:$E$32," & _

  "$E$34:$E$36,$E$38:$E$40,$J$26:$J$28,$J$30:$J$32,$J$34:$J$36,$J$38:$J$40," & _

  "$M$26:$M$28,$M$30:$M$32,$M$34:$M$36,$M$38:$M$40")) Is Nothing Then


  Set WS = ThisWorkbook.Worksheets("Sheet X")

  Set rng = WS.Range(Target.Address)

  Set C = rng.Comment

  If Not C Is Nothing Then

  C.Delete  'delete any existing comment

  End If


  If rng.Value > 0 And rng.Value <= 0.989 Then

  Do

  sReason = Application.InputBox("Please provide a brief comment on why KPI was missed", _

  Title:="Comment for cell " & rng.Address & " (in " & WS.Name & ")", Type:=2)

  Loop Until sReason <> "False"

  rng.AddComment

  rng.Comment.Visible = False

  rng.Comment.Text Text:=sReason

  End If

  End If


  Application.ScreenUpdating = True

End Sub

jski
 
Welcome to the forum. :)
You could check if formula string references the address in the source range.
Use .Range.Find and search in formula. If found then add comment to that cell.

Please upload sample workbook, which reflect your actual workbook's set up, and clearly demonstrate your issue, if you need more help.
 
Will work on that suggestion. Thanks. Here's a sample workbook...
 

Attachments

  • Sheet X Project.xlsm
    40 KB · Views: 2
Back
Top