0

I have a VBA script that displays a popup message when I click into cell.

Here's a screenshot:

enter image description here

I would like to make this a bit more user friendly and show it as Stock: 79,382

Is it possible to do something like that?

Here is my VBA:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rngStockData As Range

    With Worksheets("Stock").Range("A2").CurrentRegion
        Set rngStockData = .Offset(1).Resize(.Rows.Count - 1)
    End With

    If Target.CountLarge = 1 Then
        If Target.Row > 4 And Target.Column > 1 Then
            If Not Intersect(Target, Me.Range("A4").CurrentRegion) Is Nothing Then
                With Target.Validation
                    .Delete
                    .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator:=xlBetween
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = "Stock: " & Application.VLookup(Me.Cells(Target.Row, "A"), rngStockData, Target.Column, False)
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
            End If
        End If
    End If
End Sub
Gangrel
  • 449
  • 4
  • 20

1 Answers1

0

You can use the InputTitle for something similar, but you cannot use HTML or something to format it.

Try the Target.Validation part like this:

With Target.Validation
    .Delete
    .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator:=xlBetween
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = "Stock" ' moved this from InputMessage line
    .ErrorTitle = ""
    .InputMessage = Application.VLookup(Me.Cells(Target.Row, "A"), rngStockData, Target.Column, False)
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

Also: You can achieve something similar using cell comments too.

Add comments to cells using VBA

braX
  • 11,506
  • 5
  • 20
  • 33