+ Reply to Thread
Results 1 to 3 of 3

Selecting correct worksheet tab at end of VBA routine

  1. #1
    Registered User
    Join Date
    01-31-2018
    Location
    York
    MS-Off Ver
    Windows 7
    Posts
    4

    Selecting correct worksheet tab at end of VBA routine

    Hi,

    With much help from various sources I've put a Macro together that pastes excel data from an external (user selected) excel file into the "Active" workbook. The workbook has 2 tabs "DailyOrders" and "TEMPLATE". So far when I run the macro the data is pasted into the "DailyOrders" tab and that is it. I would like the macro to finish by having the user looking at the "TEMPLATE" tab. The Macro code so far is:

    Sub ImportData()

    Dim wb1 As Workbook
    Dim wb2 As Workbook
    Dim Sheet As Worksheet
    Dim PasteStart As Range

    Set wb1 = ActiveWorkbook
    Set PasteStart = [DailyOrders!A3]

    Sheets("DailyOrders").Select
    Cells.Select
    Selection.ClearContents

    FileToOpen = Application.GetOpenFilename _
    (Title:="Please choose a Report to Parse", _
    FileFilter:="Report Files *.xls (*.xls),")

    If FileToOpen = False Then
    MsgBox "No File Specified.", vbExclamation, "ERROR"
    Exit Sub
    Else
    Set wb2 = Workbooks.Open(Filename:=FileToOpen)

    For Each Sheet In wb2.Sheets
    With Sheet.UsedRange
    .Copy PasteStart
    Set PasteStart = PasteStart.Offset(.Rows.Count)

    End With

    Next Sheet

    End If

    wb2.Close

    End Sub


    Would someone be able to help me to add some further code that ends by selecting the "Template" tab of my workbook? If so where in the code routine should the command sit?

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Selecting correct worksheet tab at end of VBA routine

    You already have "Sheets("DailyOrders").Select"
    Can you not make the last line in the code
    `Sheets("TEMPLATE").Select`

  3. #3
    Registered User
    Join Date
    01-31-2018
    Location
    York
    MS-Off Ver
    Windows 7
    Posts
    4

    Re: Selecting correct worksheet tab at end of VBA routine

    Thanks davesexcel - Sorted!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vlookup not selecting the correct cell
    By nathandavies9 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-29-2017, 11:32 AM
  2. Selecting the Correct Formula
    By vincywoman1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-11-2014, 01:40 AM
  3. [SOLVED] Trouble Selecting Correct Row multiple matches
    By rlpowers in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-31-2013, 12:36 PM
  4. Selecting correct cell after Autofilter
    By subtilty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2011, 11:49 AM
  5. Combobox on Userform not selecting correct data
    By frostie77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2010, 05:15 PM
  6. selecting first correct argument in if statement
    By gss in forum Excel General
    Replies: 4
    Last Post: 06-09-2009, 02:27 AM
  7. [SOLVED] start up routine in worksheet
    By Colin Telfer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2006, 12:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1