Debug Print output in msgbox

larryresick

New Member
Joined
Dec 21, 2017
Messages
6
How can I get the Debug.Print immediate window results to display in a msg box once all the values are found?

Sub PlayerSessions()


Dim rngCell As Range
Dim ws As Worksheet
Dim lngLstRow As Long
Dim lngLstCol As Long
Dim strSearch As String
Dim txt As String




strSearch = InputBox("Please enter Player ID:", "Search Value")


For Each ws In Worksheets
If ws.Name <> "Combined" And ws.Name <> "Player Names" And ws.Name <> "Summary" Then
ws.Select




For Each rngCell In Range("D2", "D17")
If rngCell.Value = strSearch Then
Debug.Print (ws.Name)

End If
Next
End If

Next ws


End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
There is the option to undock the window.

Would creating a string as you are using Debug.Print work?

Code:
Sub PlayerSessions()




Dim rngCell As Range
Dim ws As Worksheet
Dim lngLstRow As Long
Dim lngLstCol As Long
Dim strSearch As String
Dim txt As String
Dim windowresults As String
Dim counter As Long


counter = 0
strSearch = InputBox("Please enter Player ID:", "Search Value")


For Each ws In Worksheets
If ws.Name <> "Combined" And ws.Name <> "Player Names" And ws.Name <> "Summary" Then
ws.Select


For Each rngCell In Range("D2", "D17")
If rngCell.Value = strSearch Then
Debug.Print (ws.Name)
If counter = 0 Then
windowresults = (ws.Name)
counter = 1
Else
windowresults = windowresults & ", " & (ws.Name)
End If
End If
Next
End If


Next ws


MsgBox windowresults


End Sub
 
Upvote 0
Thank you mrshl9898 that works splendidly (although I am not sure how you did it I will have to study that counter).
 
Upvote 0
I cleaned this up to handle empty string just to complete the thread, this is the final version:

Sub PlayerSessions()






Dim rngCell As Range
Dim ws As Worksheet
Dim strSearch As String
Dim windowresults As String
Dim counter As Long




Line1:


counter = 0
strSearch = InputBox("Please enter Player ID:", "Search Value")
If strSearch = "" Then
MsgBox "You didn't enter a player ID."
Ans = MsgBox("Do you wish to enter a PlayerID?", vbYesNo)
If Ans = vbYes Then GoTo Line1
Exit Sub
End If




For Each ws In Worksheets
If ws.Name <> "Combined" And ws.Name <> "Player Names" And ws.Name <> "Summary" Then
ws.Select




For Each rngCell In Range("D2", "D17")
If rngCell.Value = strSearch Then
Debug.Print (ws.Name)
If counter = 0 Then
windowresults = (ws.Name)
counter = 1
Else
windowresults = windowresults & ", " & (ws.Name)
End If
End If
Next
End If




Next ws


If windowresults = "" Then
MsgBox "Player is not in any sessions."
Exit Sub
End If


MsgBox "Player is in sessions " & windowresults




End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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