VBA MSGBOX displaying Multiple Value VLOOKUP

David_Sands

New Member
Joined
Jun 11, 2014
Messages
4
Hi everyone,
Hope someone can help me with this ... I'm trying to work out how to do what is displayed in the image below. The table (cells C9:AB28) are all COUNTIFS based on data on a different worksheet (see the 2nd image below) in the same workbook and when the user clicks on one of the cells (for example I've clicked on Q23 below) a MSGBOX pops up showing all the student names behind the number 17 - or in other words all the people in column D (2nd image below) who match the matrix criteria in the first image below (in this example KS3 Sub-Level 5C and KS2 Sub-Level 5C).
Really hope someone can help me with this and many thanks in advance,
Dave

FileDownloadHandler.ashx

FileDownloadHandler.ashx
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi

Try this in a command button, then perhaps move it to an event that suits you.

Code:
Application.ScreenUpdating = False
Dim holder, fx
holder = ""
For Each fx In ActiveSheet.Range("a3:a8") ' Adjust range to Suit Your Sheet
holder = holder & fx & Chr(13)
Next fx
MsgBox holder, vbOKOnly, "Populated Message Box"

Regards

Kev
 
Last edited:
Upvote 0
This Might be better for you, you can define the cell you wish to click to cause the msgbox to display.

Pop the whole thing into your vba window.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim holder, fx
holder = ""
If Intersect(ActiveCell, Range("Q23")) Is Nothing Then 'Adjust to Suit the Cell You Click to Cause the box to display
      
    Else
   
For Each fx In ActiveSheet.Range("a3:a20") ' Adjust to Suit the Range You Wish to Display
holder = holder & fx & Chr(10)
Next fx
MsgBox holder, vbOKOnly + vbInformation, "Populated Message Box"
 
End If
End Sub

Kev
 
Upvote 0
Thank you for this, however it doesn't seem to be working, I get the msgbox come up but with none of the 17 names that should appear, any ideas?


9k=




This Might be better for you, you can define the cell you wish to click to cause the msgbox to display.

Pop the whole thing into your vba window.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim holder, fx
holder = ""
If Intersect(ActiveCell, Range("Q23")) Is Nothing Then 'Adjust to Suit the Cell You Click to Cause the box to display
      
    Else
   
For Each fx In ActiveSheet.Range("a3:a20") ' Adjust to Suit the Range You Wish to Display
holder = holder & fx & Chr(10)
Next fx
MsgBox holder, vbOKOnly + vbInformation, "Populated Message Box"
 
End If
End Sub

Kev
 
Upvote 0
Have you adjusted the range in the code to suit your sheet as detailed in code
 
Upvote 0
hold fire I see you need to a selection on the names, I will have a look at it
 
Upvote 0
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim holder, fx
holder = ""
If Intersect(ActiveCell, Range("q23")) Is Nothing Then 'Adjust to Suit the Cell You Click to Cause the box to display


Else

For Each fx In ActiveSheet.Range("d9:d20") ' Adjust to Suit the Range You Wish to Display
If fx.Offset(0, 2).Value = "5C" Or fx.Offset(0, 3).Value = "5C" Or fx.Offset(0, 3).Value = "5c" Or fx.Offset(0, 2).Value = "5c" Then

holder = holder & fx & Chr(10)
End If
Next fx
MsgBox holder, vbOKOnly + vbInformation, "Populated Message Box"


End If
End Sub
 
Upvote 0
This works brilliantly, thank you so much, could I just check one more thing though, as there are 520 cells to my table, I would need to repeat this code 520 times, 1 for each different set of parameters ... is this right or is there another automated way that I could do this e.g. is it possible for your 'If' statement in the code below to reference the countifs statement in the range cell on the worksheet (in this example Q23) rather than fixed values (in this example 5C's)?

I hope you don't think I'm being cheeky asking all these questions, trust me your help is hugely appreciated.

Dave :biggrin:



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim holder, fx
holder = ""
If Intersect(ActiveCell, Range("q23")) Is Nothing Then 'Adjust to Suit the Cell You Click to Cause the box to display


Else

For Each fx In ActiveSheet.Range("d9:d20") ' Adjust to Suit the Range You Wish to Display
If fx.Offset(0, 2).Value = "5C" Or fx.Offset(0, 3).Value = "5C" Or fx.Offset(0, 3).Value = "5c" Or fx.Offset(0, 2).Value = "5c" Then

holder = holder & fx & Chr(10)
End If
Next fx
MsgBox holder, vbOKOnly + vbInformation, "Populated Message Box"


End If
End Sub
 
Upvote 0
Hi

Not a 100% sure what you are asking me but here goes. You could alter the line of code:-

If Intersect(ActiveCell, Range("q23")) Is Nothing Then 'Adjust to Suit the Cell You Click to Cause the box to display

to

If Intersect(ActiveCell, Range("q23:S77")) Is Nothing Then 'Adjust to Suit the Cell You Click to Cause the box to display

then any cell selected within this range will cause the same msgbox to be displayed. If however you need a different message box for each groupe of cells then that would be different.

Kev
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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