Okay, so here we go:
My vision:
1. I want to put a name in the textbox at the top, it then populates in the listbox (If I need a search button that's cool, otherwise filter as I type would be cool).
2. Once the name shows up in the listbox, I want to click (or double-click) the record and the information populates into the 4 textboxes below the listbox (or not if there is missing information (missing information is not something I care about, so no need for validations)
3. Once information is populated from the click or double click I want to update or add information to the sheet E_Sponsor_Add (honestly, I think both the add and update buttons do the same thing in this userform so I'm cool with one being dropped
4. I understand the clear/delete/save and close vbas, no need to change these unless it interferes with steps 1, 2, or 3.
Note: So I'm having trouble clearing the listbox at the beginning when running the userform vba (not sure what to do about that I want it to show up empty with the headers though)
Here is the dummy info on the sheet that my userform add/updates/saves to:
Future List.xlsm |
---|
|
---|
| A | B | C | D | E | F | G | H |
---|
1 | ID | Prospective Gain | Sponsor Rate | Sponsor Last,First Name | Cell Phone # | Email | Submitted By | Updated |
---|
2 | 1 | SMITH,ADAM | ITC | PIE,APPLE | (909) 876-5234 | sweet@gmail.com | TRULY,YOURS | 21-Jan-21 10:11:00 AM |
---|
3 | 2 | WASHINGTON, JOHN | PRC | PUMPKIN,PEACHES | (454) 363-2821 | ppumpkin@aol.com | TRULY,YOURS | 3-Mar-21 12:00:00 PM |
---|
4 | 3 | DOE,JANE | HTC | PUMP,DESTINY | (876) 345-9012 | pump@yahoo.com | TRULY,YOURS | 13-Apr-21 1:45:00 PM |
---|
5 | 4 | MARCIANO,LUCKY | GMC | TOTO,AFRICA | (123) 456-7890 | toto.africa@gmail.com | TRULY,YOURS | 18-Feb-21 6:00:00 AM |
---|
6 | 5 | CAPONE,AL | FCC | GILMORE,HAPPY | (213) 495-0098 | happy.gilmore@yahoo.com | TRULY,YOURS | 22-Jul-21 3:00:00 PM |
---|
7 | 6 | MONTANA,TONY | ATC | FIELDS,STRAWBERRY | (315) 909-7654 | straw.fields@aol.com | TRULY,YOURS | 1-Jun-21 1:00:00 AM |
---|
8 | 7 | LOPEZ,ANGELINA | DCC | BOND,JAMES | (555) 459-8989 | james.bond@gmail.com | TRULY,YOURS | 31-Mar-20 8:00:00 AM |
---|
|
---|
Here is my VBA Code (if it needs editing please let me know, I'm not smart enough yet to create code just copy from tutorials and understand somewhat)
USERFORM:
Private Sub UserForm_Activate()
Call Refresh_Data
End Sub
Sub Refresh_Data()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("E_Sponsor_Add")
Dim last_row As Long
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
With Me.lstDatabase
.ColumnHeads = True
.ColumnCount = 8
.ColumnWidths = "0,120,50,120,90,200,0,0"
If last_row = 1 Then
.RowSource = "E_Sponsor_Add!A2:H2"
Else
.RowSource = "E_Sponsor_Add!A2:H" & last_row
End If
End With
End Sub
Private Sub cmdADD_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("E_Sponsor_Add")
Dim last_row As Long
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
sh.Range("A" & last_row + 1).Value = "=Row()-1"
sh.Range("C" & last_row + 1).Value = Me.txtRATE.Value
sh.Range("D" & last_row + 1).Value = Me.txtNAME.Value
sh.Range("E" & last_row + 1).Value = Me.txtPHONE.Value
sh.Range("F" & last_row + 1).Value = Me.txtEMAIL.Value
sh.Range("G" & last_row + 1).Value = Application.UserName
sh.Range("H" & last_row + 1).Value = Now
Me.txtRATE.Value = ""
Me.txtNAME.Value = ""
Me.txtPHONE.Value = ""
Me.txtEMAIL.Value = ""
Call Refresh_Data
End Sub
Private Sub cmdCLEAR_Click()
Me.txtPG.Value = ""
Me.txtRATE.Value = ""
Me.txtNAME.Value = ""
Me.txtPHONE.Value = ""
Me.txtEMAIL.Value = ""
End Sub
Private Sub cmdCLOSE_Click()
Unload addSponsorE
End Sub
Private Sub cmdDELETE_Click()
If Me.TextBox1.Value = "" Then
MsgBox "Select Sponsor to Delete"
Exit Sub
End If
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("E_Sponsor_Add")
Dim Selected_row As Long
Selected_row = Application.WorksheetFunction.Match(CLng(Me.TextBox1.Value), sh.Range("A:A"), 0)
sh.Range("A" & Selected_row).EntireRow.Delete
Call Refresh_Data
Me.txtRATE.Value = ""
Me.txtNAME.Value = ""
Me.txtPHONE.Value = ""
Me.txtEMAIL.Value = ""
Me.TextBox1.Value = ""
End Sub
Private Sub cmdSAVE_Click()
ThisWorkbook.Save
MsgBox "Sponsor Information Saved"
End Sub
Private Sub cmdUPDATE_Click()
If Me.TextBox1.Value = "" Then
MsgBox "Select Sponsor to Update"
Exit Sub
End If
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("E_Sponsor_Add")
Dim Selected_row As Long
Selected_row = Application.WorksheetFunction.Match(CLng(Me.TextBox1.Value), sh.Range("A:A"), 0)
sh.Range("C" & Selected_row).Value = Me.txtRATE.Value
sh.Range("D" & Selected_row).Value = Me.txtNAME.Value
sh.Range("E" & Selected_row).Value = Me.txtPHONE.Value
sh.Range("F" & Selected_row).Value = Me.txtEMAIL.Value
sh.Range("G" & Selected_row).Value = Application.UserName
sh.Range("H" & Selected_row).Value = Now
Me.txtRATE.Value = ""
Me.txtNAME.Value = ""
Me.txtPHONE.Value = ""
Me.txtEMAIL.Value = ""
Me.TextBox1.Value = ""
Call Refresh_Data
End Sub
Private Sub lstDatabase_Click()
Me.TextBox1.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0)
Me.txtRATE.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)
Me.txtNAME.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)
Me.txtPHONE.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)
Me.txtEMAIL.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)
End Sub
----------------------------------
MODULE CODE:
Sub AssignSponsor_Click()
addSponsorE.Show
End Sub
-----------------------------------
USERFORM IMAGE: