Switching Worksheets in Macro

I

Ian B.

I'm making a macro to switch do a presentation of some work in Excel, the
charts being shown change each time there is a recalculation as random data
is relied upon. I can't figure out how to change the worksheet though in
the macro, maybe I'm just missing something. The rest of the macro I
managed to make just from the VB help file. Any ideas? Just to indicate
what I'm trying to do I've included my code thus far below.

TIA,
Ian

---
Sub MacroX()

Application.DisplayFullScreen = True
a = 0
Do
Calculate
Application.Wait (Now + TimeValue("0:00:10"))
a = a + 1
Loop Until a = 5
***Switch Workdsheet Wanted Here***
a = 0
Do
Calculate
Application.Wait (Now + TimeValue("0:00:10"))
a = a + 1
Loop Until a = 5

End Sub
---
 
I

Ian B.

Dave Peterson said:
How about adding:

worksheets("mysheetnamehere").select

That works :), cheers!! Sheets("sheetname).Activate is what I managed to
find in the end via the help. Seems to work with 'Sheets' as it will work
for my charts and worksheets. I have no idea of the difference between
..activate and .select though??

Ian
 
C

Chip Pearson

Ian,

Under most circumstances, Select and Activate behave the same
way. The difference between them arises with more than one
worksheet is selected, in other words, two or more sheets are
grouped. In this case, Select will unselect all the presently
selected sheets and then select (and activate) the specified
sheet. Activate will keep all the presently selected sheets
selected, and change activate the specified sheet.

To see the difference between Select and Activate, group all the
worksheets together (manually select the first sheet, hold down
the SHIFT key and select the last sheet) and then run the two
following macros:

Sub TestSelect()
Sheets(2).Select
End Sub

Sub TestActivate()
Sheets(2).Activate
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
E

Earl Kiosterud

To add to that, you can have many sheets selected (grouped), but only one of
them will be active. It'll be the one in front -- the one you see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top