Need advise on whether or not what I want to do is even possible... Pop up box that auto-populates next available...

MJ72

Board Regular
Joined
Aug 17, 2021
Messages
64
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello All,
I currently have a spreadsheet that acts like a call log (Sheet1)(Call Log). In one of the cells I have a drop down menu that allows for a "yes" or "no" answer. I'd like to create a code that when the answer is "yes" a pop box appears with another drop down menu with 3 choices (let's say A, B, or C) and then have the selected answer auto populate into the next available cell in a specific column of a table (cells M3:M12)on another sheet of the workbook (Sheet 5)(P&A). Is this possible and if so, how? Thanks.
 
Thank you Gokhan, I will definitely try this. As for your earlier concerns, I will be the only one using these forms for now. I'm creating a CRM to use at work. I would normally just use something like Salesforce for these things but I currently work for a non-profit and we don't have the budget for actual software, so I'm attempting, with my limited excel knowledge to build one myself. It's taking awhile but it is coming along. I thank you for the help, and I'm sure I will have more coding questions before the workbook is done.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
No? :) Basically, you said the same thing earlier. Tbh it does help to visualize better, but you haven't told anything about the concerns I mentioned. So I will just try to help with your question. You can always ask for improvements anyway.

If these two sheets will not be deleted then assign codenames to them in VBA Editor properties pane. Select the sheet in Project pane and enter "CallLog" and "PaA" for the (Name) property. You can change the names of course, but if you do also change the references in other places below.

Paste the following at the top before any subs in any standard module (insert one if there are none).

VBA Code:
Public TargetRow As Long
Public SelectedOption As String

Paste the following in CallLog sheet module.

VBA Code:
Dim bYesAlready As Boolean

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not (Intersect(Target, CallLog.Columns("N:N")) Is Nothing) Then
       
        If Target.Cells.Count > 2 Or Target.Row = 1 Then Exit Sub
       
        If UCase(Target.Value) = "YES" Then
           
            If bYesAlready Then Exit Sub
           
            TargetRow = Target.Row
            frmOptionSelection.Show
           
        End If
       
    End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not (Intersect(Target, CallLog.Columns("N:N")) Is Nothing) Then
        If Target.Cells.Count > 1 Then Exit Sub
        If UCase(Target.Value) = "YES" Then
            bYesAlready = True
        Else
            bYesAlready = False
        End If
    End If

End Sub

Insert a new userform, name it "frmOptionSelection" and add 3 Option Buttons, I kept the names default. Add a command button and name it "cmdSelect".

Paste the following to the userform's module.

VBA Code:
Private Sub cmdSelect_Click()

    If SelectedOption <> "" Then

        Dim rng As Range
       
        Set rng = PaA.Range("L1").CurrentRegion
       
        Dim NextRow As Long
       
        NextRow = rng.Rows.Count + 1
       
        PaA.Range("L" & NextRow).Value = CallLog.Range("H" & TargetRow).Value ' Date
        PaA.Range("M" & NextRow).Value = SelectedOption ' SelectedOption
        PaA.Range("N" & NextRow).Value = CallLog.Range("A" & TargetRow).Value ' Company
        PaA.Range("O" & NextRow).Value = CallLog.Range("C" & TargetRow).Value ' Contact
        'PaA.Range("P" & NextRow).Value = CallLog.Range("H" & TargetRow).Value ' Interaction
       
        Set rng = Nothing
       
        SelectedOption = ""

        Me.Hide

    End If

End Sub

Private Sub OptionButton1_Click()

    SelectedOption = "A"

End Sub

Private Sub OptionButton2_Click()

    SelectedOption = "B"

End Sub

Private Sub OptionButton3_Click()

    SelectedOption = "C"

End Sub

Private Sub UserForm_Activate()

    Me.Top = Application.Top + Application.Height / 2 - Me.Height / 2
    Me.Left = Application.Left + Application.Width / 2 - Me.Width / 2
   
    Me.OptionButton1.Value = False
    Me.OptionButton2.Value = False
    Me.OptionButton3.Value = False
   
    SelectedOption = ""
   
    cmdSelect.SetFocus
   
End Sub

Private Sub UserForm_Initialize()

    Me.StartUpPosition = 0

End Sub

Change the SelectedOption variables to the suitable choices under OptionButton#_Click events.
Also, I was not sure which column the option was going to be pasted and assumed M. Change it and the Interaction columns as necessary.

The option form will not show if the Yes/No selection cell already has a "yes" on it when you select it. However, as is, if a wrong selection is made there is no correction other than going into PaA sheet and manually change the option.
@Gokhan Aycan Ok, so I've gotten something wrong and it's because VBA is still Greek to me... Don't suppose you feel like taking a look at a test workbook I created?
 
Upvote 0
Yeah, I can later tonight. You can provide a download link here I suppose.
 
Upvote 0
You can use a file sharing site, and provide the link. You are correct in that file attachments are not allowed here.
 
Upvote 0
Upvote 0
Ok, what you need to do at this stage:

1. You forgot the first line in worksheet_selectionchange event (either that or I mis-deleted myself :) ):
If Not (Intersect(Target, CallLog.Columns("N:N")) Is Nothing) Then

2. Paste the next to frmOptionSelection module (right click userform in project pane and view code).

I have added the code for the 4th and 5th option buttons, you just need to change "A", "B", etc. in OptionButton#_Click events to the corresponding option text.

VBA Code:
Private Sub cmdSelect_Click()

    If SelectedOption <> "" Then

        Dim rng As Range
      
        Set rng = PaA.Range("L1").CurrentRegion
      
        Dim NextRow As Long
      
        NextRow = rng.Rows.Count + 1
      
        PaA.Range("L" & NextRow).Value = CallLog.Range("H" & TargetRow).Value ' Date
        PaA.Range("M" & NextRow).Value = SelectedOption ' SelectedOption
        PaA.Range("N" & NextRow).Value = CallLog.Range("A" & TargetRow).Value ' Company
        PaA.Range("O" & NextRow).Value = CallLog.Range("C" & TargetRow).Value ' Contact
        'PaA.Range("P" & NextRow).Value = CallLog.Range("H" & TargetRow).Value ' Interaction
      
        Set rng = Nothing
      
        SelectedOption = ""

        Me.Hide

    End If

End Sub

Private Sub OptionButton1_Click()

    SelectedOption = "A"

End Sub

Private Sub OptionButton2_Click()

    SelectedOption = "B"

End Sub

Private Sub OptionButton3_Click()

    SelectedOption = "C"

End Sub

Private Sub OptionButton4_Click()

    SelectedOption = "D"

End Sub

Private Sub OptionButton5_Click()

    SelectedOption = "E"

End Sub

Private Sub UserForm_Activate()

    Me.Top = Application.Top + Application.Height / 2 - Me.Height / 2
    Me.Left = Application.Left + Application.Width / 2 - Me.Width / 2
  
    Me.OptionButton1.Value = False
    Me.OptionButton2.Value = False
    Me.OptionButton3.Value = False
    Me.OptionButton4.Value = False
    Me.OptionButton5.Value = False
  
    SelectedOption = ""
  
    cmdSelect.SetFocus
  
End Sub

Private Sub UserForm_Initialize()

    Me.StartUpPosition = 0

End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,212,928
Messages
6,110,734
Members
448,294
Latest member
jmjmjmjmjmjm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top