Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Define a sheet name to be returned to later.

Posted on 2011-02-25
8
Medium Priority
?
247 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
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
Industry Leaders: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

972 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