Upon selection of item in table row, need msg box to appear and have resulting number entered in table

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,121
I have a table called npss_quote. The header row is A10:M10 with the data starting in row 11. Column B for each row in the table has a data validation list referring to a list of 7 items. Upon the selection of one of the items, Activities, I want a pop up msg box to appear. This allows you to enter a figure and when you press ok, it puts the figure into column M of the table row. Can someone help me with the vba code please?
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
16,691
This is sheet code for a change event. Right-click the sheet tab, choose "View Code" and paste the code below into the VBE window that opens.
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LO As ListObject, c As Range, x As Variant, Prompt As String
Set LO = Me.ListObjects("npss_quote")
If Not Intersect(Target, LO.Range.Columns(2)) Is Nothing Then
    Application.EnableEvents = False
    For Each c In Intersect(Target, LO.Range.Columns(2))
        If c.Value = "Activities" Then
            Prompt = "Enter a figure for cell: " & c.Offset(0, 11).Address
            x = Application.InputBox(Prompt, Type:=1)
            If x = False Then
                Application.EnableEvents = True
                Exit Sub
            Else
                c.Offset(0, 11).Value = x
            End If
        End If
    Next c
End If
Application.EnableEvents = True
End Sub
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,121
Thanks Joe, I already had this code that someone helped me with and I forgot that I already had the code. It adds a new column on to the end instead of putting the activity cost into the column called Activities. Can you help me change the code please so when you press ok on the message box, it puts the figure in the activity column for the current row in the table please?
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,121
Sorry, I forgot to include the code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'ActiveSheet.Unprotect
  Dim ans As String
  'I suggest this go to the start before turning off the events.
  If Target.Count > 1 Or IsEmpty(Target) Then Exit Sub
  '
  On Error GoTo App_Events
  If Not Intersect(Target, Range("A:A,B:B")) Is Nothing Then
    Application.EnableEvents = False
    Select Case Target.Column
      Case 1
        If Target.Value < Date Then
          If MsgBox("This input is older than today !....Are you sure that is what you want ???", vbYesNo) = vbNo Then
            Target.Value = ""
          End If
        End If
      Case 2
        If LCase(Target.Value) = LCase("Activities") Then
          Do
            ans = InputBox("Please enter the Activities cost." & _
              vbCrLf & "************************************" & vbCrLf & _
              "To change an activity cost, select Activities from the Service list again.")
            If ans <> "" Then
              Cells(Target.Row, "N") = ans
              Exit Do
            Else
              MsgBox ("You must enter a Activities cost.")
            End If
          Loop
        End If
    End Select
  End If
App_Events:
  Application.EnableEvents = True
  'ActiveSheet.Protect
End Sub
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,283
Office Version
2013
Platform
Windows
Hi Dave
Doesn't this part do that ??

Code:
If ans <> "" Then
   Cells(Target.Row, "N") = ans
   Exit Do
End If
 

Forum statistics

Threads
1,084,776
Messages
5,379,812
Members
401,629
Latest member
LEMANOIS

Some videos you may like

This Week's Hot Topics

Top