Userform VBA code using 2 criteria to populate 1 cell

Pi_Lover

Board Regular
Joined
Nov 3, 2023
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I am attempting my first Userform. The purpose of the Userform is to enter in data to populate a cell with 2 different criteria. The first criteria will be column specific, while the second will be row specific, but the row will be determined by the data entered into a text box. Essentially, I want the row criteria to basically function like a Vlookup, or like a search function, to find the correct row, and then the 2nd text box will determine the column. Is this possible? See attachments below for reference.

Userform.png
Tracker.png
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I'm not sure I fully understand what you are asking. But I have put together a mock up of a user form where you type in the Inst Tag #, and it looks up and populates that text boxes under the look up:

Look up table:
1719354054502.png


User form as I type:
1719354094379.png


User form once I finish typing a value that matches to the table (column A):
1719354141105.png

(note, the four text boxes are auto-populated, once the tag # is completely entered in)

Here's the VBA code to accomplish this:
VBA Code:
Private Sub TextBox1_Change()
Dim Lookup As String
Dim LookupRow As Long
Dim StandClm  As Integer
Dim InstInClm As Integer
Dim VendInClm As Integer
Dim InstEnClm As Integer

On Error Resume Next
Lookup = Me.TextBox1.Value
LookupRow = Application.Match(Lookup, Range("A:A"), 0)

StandClm = 2
InstInClm = 3
VendInClm = 4
InstEnClm = 5

Me.TextBox2 = Cells(LookupRow, StandClm)
Me.TextBox3 = Cells(LookupRow, InstInClm)
Me.TextBox4 = Cells(LookupRow, VendInClm)
Me.TextBox5 = Cells(LookupRow, InstEnClm)

End Sub
 
Upvote 0
Alternatively, if you are looking to populate the Excel cells, based off the data you plug into the lower text boxes, this code will do that:
VBA Code:
Private Sub CommandButton1_Click()

Dim Lookup As String
Dim LookupRow As Long
Dim StandClm  As Integer
Dim InstInClm As Integer
Dim VendInClm As Integer
Dim InstEnClm As Integer

On Error Resume Next
Lookup = Me.TextBox1.Value
LookupRow = Application.Match(Lookup, Range("A:A"), 0)

StandClm = 2
InstInClm = 3
VendInClm = 4
InstEnClm = 5

Cells(LookupRow, StandClm) = Me.TextBox2
Cells(LookupRow, InstInClm) = Me.TextBox3
Cells(LookupRow, VendInClm) = Me.TextBox4
Cells(LookupRow, InstEnClm) = Me.TextBox5

End Sub

Table before I run this user form:
1719354682524.png


User form before I run it:
1719354768314.png


Table after I run the user form:
1719354789862.png
 
Upvote 1
Solution
This is great! Thank you, this is exactly what I am wanting to do. Much appreciation
 
Upvote 0
@Max1616 This works perfectly, but I have run into an issue. Each column of data to be entered into the sheet may be performed at different dates and times. Meaning I may add progress of "1" for Stands today, then "1" Instrument installed the following day. When I do this, it clears the data entered in for the Stands on the worksheet. Is there a work around for this?
 
Upvote 0
@Pi_Lover , This would only update the cell(s) if there is data in the text boxes:
VBA Code:
Private Sub CommandButton1_Click()

Dim Lookup As String
Dim LookupRow As Long
Dim StandClm  As Integer
Dim InstInClm As Integer
Dim VendInClm As Integer
Dim InstEnClm As Integer

On Error Resume Next
Lookup = Me.TextBox1.Value
LookupRow = Application.Match(Lookup, Range("A:A"), 0)

StandClm = 2
InstInClm = 3
VendInClm = 4
InstEnClm = 5

If Me.TextBox2 <> "" Then Cells(LookupRow, StandClm) = Me.TextBox2
If Me.TextBox3 <> "" Then Cells(LookupRow, InstInClm) = Me.TextBox3
If Me.TextBox4 <> "" Then Cells(LookupRow, VendInClm) = Me.TextBox4
If Me.TextBox5 <> "" Then Cells(LookupRow, InstEnClm) = Me.TextBox5

End Sub
 
Upvote 1

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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