MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Sheet sorting question


Posted by G-man on March 09, 2001 10:04 AM

After sorting my worksheets alphabetically, how can I make the first sheet the active sheet?

Thanks,

G-man


Posted by G-man on March 09, 2001 10:12 AM

Actually, what I am really looking for is how to make the first sheet the active sheet after sorting and then activating random sheets.
The first sheet name will vary each time a new workbook is created.

Thanks,

G.

Posted by David Hawley on March 09, 2001 1:12 PM


Hi G-Man

This will do it.


Sub TryThis()
Dim ShtNum As Integer, ShtCount As Integer

Sheets(1).Activate
ShtCount = Sheets.Count
Randomize 'Initialize random-number generator.
'Random Number between 1 and Sheets.Count
ShtNum = Int((ShtCount * Rnd) + 1)
Sheets(ShtNum).Activate

End Sub


Dave

OzGrid Business Applications