Solved

Define a sheet name to be returned to later.

Posted on 2011-02-25
8
242 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 25 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 92

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 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 25 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

617 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