VBA code With multiple criteria and multiple results in userform.

KestutisTower

New Member
Joined
Jun 2, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone. Im new to this forum. AND i'm stuck🤦‍♂️😅

I'm creating a userform with two comboboxes ant a textbox. the idea is to retrieve information from a table with data populated via other userform and date is autogenerated.

Customer:​
Product:​
Date:​
JOHNTV22/05/01
LINDATV22/05/01
JOHNRADIO22/05/02
LINDAPC22/05/02
SUSIEPC22/05/01
JOHNPC22/05/01

Combobox1 rowsource is colum "Customer" and Combobox2 rowsource is "Date". What I need to do, is when I input selection in Combobox1 and Combobox2, data to appear in textbox1. As you can see, there are multiple results in some cases. So ... basically I need a VBA code with multiple criteria, to gel multiple results and to show all that in textbox1.

Hope I presented my problem clearly.
All help will be appreciated🙏
 
Thank you Dante!!! worked magick! Saved this for me 🙏 :giggle:
One last question.

In the code for module 1.( post#3)

VBA Code:
.Cells(iRow, 10) = UserForm1.txtPreke.Value & "   " & UserForm1.txtKiekis.Value & " vnt." & "   " & UserForm1.txtKomentaras.Value & " - "

At the end I want to add corresponding value ( or text ) from column E. In my understanding I need to make a variable of some sort. Maybe range?
I understand this is not your code, but maybe you could explain to me how to achieve this.
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I will gladly help you with the code, but you must create another thread, as it corresponds to another theme.
 
Upvote 0
I will gladly help you with the code, but you must create another thread, as it corresponds to another theme.
Hi, I was wondering if there is a way to put the items found in to textbox instead of listbox. Your previous solution worked like magic, but I need to add that text (listed items) to other textbox text, and if it was in textbox format, that would make my life a bit easier . :) Thank you for your time.
 
Upvote 0
I do not agree with putting records in a textbox, it is a bad practice, for that there are controls with a defined objective.
But it's your project, and that way you get experience.

Change this:
Rich (BB code):
Sub FilterData()
  Dim cmb1 As Variant, cmb2 As Variant
  Dim i As Long
  
  Textbox1 = ""
  For i = 1 To UBound(a)
    If ComboBox1.Value = "" Then cmb1 = a(i, 1) Else cmb1 = ComboBox1.Value   '1 = column A - names
    If ComboBox2.Value = "" Then cmb2 = a(i, 11) Else cmb2 = ComboBox2.Value  '11 = column K - dates
    If a(i, 1) = cmb1 And a(i, 11) = CDate(cmb2) Then                         '1 = A, 11 = K
       Textbox1.value = Textbox1.value & a(i, 10) & vbcr                                          '10 = J
    End If
  Next
End Sub

Note: The multiline property of the texbox must be true.
 
Upvote 0
Solution
loo
I do not agree with putting records in a textbox, it is a bad practice, for that there are controls with a defined objective.
But it's your project, and that way you get experience.

Change this:
Rich (BB code):
Sub FilterData()
  Dim cmb1 As Variant, cmb2 As Variant
  Dim i As Long
 
  Textbox1 = ""
  For i = 1 To UBound(a)
    If ComboBox1.Value = "" Then cmb1 = a(i, 1) Else cmb1 = ComboBox1.Value   '1 = column A - names
    If ComboBox2.Value = "" Then cmb2 = a(i, 11) Else cmb2 = ComboBox2.Value  '11 = column K - dates
    If a(i, 1) = cmb1 And a(i, 11) = CDate(cmb2) Then                         '1 = A, 11 = K
       Textbox1.value = Textbox1.value & a(i, 10) & vbcr                                          '10 = J
    End If
  Next
End Sub

Note: The multiline property of the texbox must be true.
Looks like you have saved my day again 😅 BIG THANKS!
 
Upvote 0

Forum statistics

Threads
1,223,712
Messages
6,174,031
Members
452,542
Latest member
Bricklin

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