Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Define a sheet name to be returned to later.

Posted on 2011-02-25
8
Medium Priority
?
244 Views
Last Modified: 2012-05-11
I need to leave a current sheet and return to it. How do I set this up? I have tried many different ways, but can't seem to get it to work.
Dim CurSht As Worksheet
  
  Set CurSht = ActiveSheet
   MsgBox "current sheet=" & CurSht

Open in new window

0
Comment
Question by:CRHIV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 6

Accepted Solution

by:
FernandoFernandes earned 100 total points
ID: 34981654
You can do it with Ctrl+PgUp and Ctrl+PgDown
also, the code you wrote is not good...
it should be like this, but anyway, it doesn't do what you want it to do... it just pops the activesheet's name...
Dim CurSht As Worksheet
  
  Set CurSht = ActiveSheet
   MsgBox "current sheet=" & CurSht.Name

Open in new window

0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 34981819
to return to it later...


Dim CurSht As Worksheet
  
  Set CurSht = ActiveSheet

'more code

CurSht.Select

Open in new window

0
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 100 total points
ID: 34981826
A little better:



Dim CurSht As Worksheet
  
  Set CurSht = ActiveSheet

'more code

With CurSht
    .Parent.Activate
    .Select
End With

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:CRHIV
ID: 34983262
I saved the variable CurSht to another sheet that the user has to check for changes, then send to the printer. I can't get the program to recognize the CurSht variable again.
Unload Me
        Sheets("napa").Select
        Sheets("NAPA").Range("K23") = CurSht
End Sub




Sub Rectangle124_Click()
    Dim CurSht As String
    Dim STDprinter As String
    CurSht = Range("K23").Value
    STDprinter = Application.ActivePrinter
    Application.ActivePrinter = "OKI MICROLINE 1120 on Ne00:"
    Sheets("NAPA").PrintOut
    Application.ActivePrinter = STDprinter                'change back to standard printer
   MsgBox "Current Sheet=" & CurSht
    Sheets(CurSht).Select

End Sub

Open in new window

0
 

Author Comment

by:CRHIV
ID: 34983797
After working with it some more, It's picking it up. But the code seems to stop after printing the document.
When it gets to the Rectangle124_click(), I don't get any MsgBox replies.
Unload Me
        Sheets("napa").Select
        Sheets("NAPA").Range("K23") = CurSht
        CurSht = ""
        MsgBox "cursht=" & CurSht
        
        CurSht = Range("K23")

        MsgBox "CurSht=" & CurSht

End Sub

'Does not work below here, except for the print


Sub Rectangle124_Click()
    Dim CurSht As String
    Dim STDprinter As String
    CurSht = Range("K23")
    STDprinter = Application.ActivePrinter
    Application.ActivePrinter = "OKI MICROLINE 1120 on Ne00:"
    Sheets("NAPA").PrintOut
    Application.ActivePrinter = STDprinter                'change back to standard printer
    MsgBox "CurSht=" & CurSht
    Sheets("CurSht").Select
    MsgBox "CurSht=" & CurSht
    Sheets("Sheet7").Select


End Sub

Open in new window

0
 

Author Comment

by:CRHIV
ID: 34984799
Never mind, Had the sub in two places.

Thanks for your help.
0
 
LVL 24

Expert Comment

by:Tracy
ID: 35225362
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question