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
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