How to List all For Loop variables in a MsgBox?

CatLadee

New Member
Joined
Sep 7, 2018
Messages
29
Hi all,

I am just starting my VBA journey and am 4 weeks into a class to learn it. I'm trying to show the entire list of variables in the For Next Loop in a message box, a la:

1 School MASCOT
2 School MASCOT
3 School MASCOT
...

But I can only get it to show the last school in the loop. I understand why it's only showing the last school, since it replaced all the others in the loop, but don't know how to have a message box list all the schools from 1 to 20 from that loop. Thanks in advance to whoever helps me - I'm spinning my wheels and already think you're the best for helping. The CatLadee


Code:
Sub SchoolList()

Dim rngIndex As Range
Dim Table_Anchor As Range
Dim Cell As Range
Dim strList As String
Dim str As String
   
With Worksheets("Data").Range("Table_Anchor")
     Set rngIndex = Range(.Offset(1, 0), .Offset(1, 0).End(xlDown))
End With
      
      For Each Cell In rngIndex
           str = Cell.Offset(0, 0) & vbTab & Cell.Offset(0, 1) & " " & UCase(Cell.Offset(0, 7)) & vbNewLine
      Next Cell
    
[COLOR=#0000ff]strList = str & vbNewLine <<< Needs help here[/COLOR]

MsgBox strList

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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