Display found results in MsgBox

Maartenn

New Member
Joined
Aug 26, 2015
Messages
5
Hello everyone.

I have an issue I really can't get my head around. I have a Sheet called "Crediteuren" with all creditors of my company, containing the following information:

Col A: Name creditor
Col B: Number creditor
Col C: Category
Col D: Contact person
Col E: E mail address
Col F: Telephone number
Col G: Quick look-up

There are three different, predefined, categories "Lab", "IT" and "A&R".

I have created a UserForm that finds the category in Column C, using the following code:

Code:
Private Sub CommandButton4_Click()

Dim cat As String
Dim lastrow As Integer
Dim i As Integer

cat = ComboBox2.Value
rng = Sheets("Crediteuren").Range("A1000").Text
lastrow = Sheets("Crediteuren").Range("A1000").End(xlUp).Row

'i = 2 meams that the loop starts looking from row 2 To lastrow.
For i = 2 To lastrow
    If Cells(i, 3) = cat Then
    
    MsgBox "Found", vbOKOnly
    End If
    
Next i

Unload Me

End Sub

What this code does (obviously) is displaying a MsgBox for each time the set category in ComboBox2 is found.
Which is awesome of course, but What I would like is one MsgBox with a list of the Creditors that match the category String I am looking for. This MsgBox would look like:

The following creditors match the criteria:
'Hit 1' Col A & Col B
'Hit 2' Col A & Col B
etc. etc.

Does anybody has to solution to this problem?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Minor detail: this code used to work, now it doesn't anymore for a reason I can't explain. Must've changed something, but can't figure out what!

Right now I have:

Code:
Private Sub CommandButton4_Click()

Dim cat As String
Dim lastrow As Integer
Dim i As Integer

cat = ComboBox2.Value
lastrow = Sheets("Crediteuren").Range("A1000").End(xlUp).Row

If ComboBox2 = vbNullString Then
MsgBox "Selecteer een categorie", vbCritical
End If
Exit Sub


'i = 2 meams that the loop starts looking from row 2 To lastrow.
For i = 2 To lastrow
'If column looked in equals cat then. Column looked into is col 3.
    If Cells(i, 3) = cat Then
    
    MsgBox "Found", vbOKOnly
    End If
    
Next i

Unload Me

End Sub

Question however, remains the same as above.
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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