drop down list for comment

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
is there anyway to have a selection list to choose from instead of writing a comment in the comment box?

Here is what I would like to do:

If any cell in range H7:H37 , J7:J37, L7:L37 (which are populated by a validation list) is less than 5, then a comment box would pop up offering the following choices:

Too much time
Too late
Not enough teamwork
etc
etc
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,734
Office Version
2007
Platform
Windows
Create a userform with the following:




Put the following code in the userform

Code:
Public cel As String    'At the beginning of all the code


Private Sub CommandButton1_Click()
  If ComboBox1.Value = "" Or ComboBox1.ListIndex = -1 Then
    MsgBox "Select a choice"
    Exit Sub
  End If
  With Range(cel)
    If .Comment Is Nothing Then .AddComment
    .Comment.Visible = True
    .Comment.Text Text:=ComboBox1.Value
    .Comment.Shape.TextFrame.AutoSize = True
  End With
  Unload Me
End Sub


Private Sub CommandButton2_Click()
  Unload Me
End Sub
Put the following code in the events on the sheet.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("H7:H37, J7:J37, L7:L37")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "" Then Exit Sub
    If Target.Value < 5 Then
      With UserForm1
        .cel = Target.Address
        .Show
      End With
    End If
  End If
End Sub
SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.
 

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
I'm not sure what went wrong but I get this message






Create a userform with the following:




Put the following code in the userform

Code:
Public cel As String    'At the beginning of all the code


Private Sub CommandButton1_Click()
  If ComboBox1.Value = "" Or ComboBox1.ListIndex = -1 Then
    MsgBox "Select a choice"
    Exit Sub
  End If
  With Range(cel)
    If .Comment Is Nothing Then .AddComment
    .Comment.Visible = True
    .Comment.Text Text:=ComboBox1.Value
    .Comment.Shape.TextFrame.AutoSize = True
  End With
  Unload Me
End Sub


Private Sub CommandButton2_Click()
  Unload Me
End Sub
Put the following code in the events on the sheet.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("H7:H37, J7:J37, L7:L37")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "" Then Exit Sub
    If Target.Value < 5 Then
      With UserForm1
        .cel = Target.Address
        .Show
      End With
    End If
  End If
End Sub
SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.
 

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
Sorry about that. I keep getting a compile error. Method or data member not found
 

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
Okay. I did get that resolved. I had 2 userforms created.

But now, I keep getting an object required error code

Any ideas?
 

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
I think it might be looking for the list but there isn't one in the code. How would I add that?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,734
Office Version
2007
Platform
Windows
You can put the complete error message and on which line of the macro it stops.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,734
Office Version
2007
Platform
Windows
Within the userform, you must create a ComboBox with the name of ComboBox1.
You must also create in the userform 2 buttons, commandbutton1 and commandbutton2
 

Forum statistics

Threads
1,081,513
Messages
5,359,226
Members
400,521
Latest member
smarty1995

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top