Results 1 to 4 of 4

Selecting a sheet based on Input from a MsgBox

Threaded View

  1. #1
    Registered User
    Join Date
    02-27-2019
    Location
    Hagerstown, MD
    MS-Off Ver
    2010
    Posts
    2

    Question Selecting a sheet based on Input from a MsgBox

    OK- first post. Also first time writing a macro.
    So I am trying to build a macro to ask a user to enter a date, and based on the date entered it will go to a shared drive and pull certain data from different files/sheets. Problem is there is a file that has different numbered tabs for the days of the month, and it is not able to select that day's tab.

    Ive found that I am getting an "Subscript out of range error" because even though I activate this second workbook (with the tabs as days) it is trying to open the numbered tab on the workbook I want to pull the data in to. I have worked on this for about a week with no success so now I am asking for smarter people for help.

    Here is my code:
    ------------------------------------
    Sub Update_Template()
    
    Dim MidFile1 As String
    Dim sDay As String
    Dim sMonth As String
    Dim sYear As String
    Dim sDate As String
    
    Dim MyFolder As String
    Dim MyFolder1 As String
    
    Dim wb1 As String
    Dim wb2 As String
    
    
    
    MidFile1 = InputBox("Please enter a date")
        If MidFile1 = "" Then
            Exit Sub
        End If
    
    
    
    sDay = Format(MidFile1, "d")
    sMonth = Format(MidFile1, "mm")
    sYear = Format(MidFile1, "yyyy")
    sDate = Format(MidFile1, "yyyymmdd")
    
    'To confirm the day is correct
    MsgBox ("sDay is " & sDay)
    
    MyFolder = "G:\Groups\Acculynk\UBER\Wells Checks - New\"
    MyFolder1 = "G:\Groups\Acculynk\New Balance DP\Amanda\Meta\"
    
    wb1 = "Wells Check (New2) " & sDate & ".xlsx"
    wb2 = sYear & "." & sMonth & ".xlsx"
    
    'Open and copy data from Uber
    Sheets("Wells_Check").Select
    [A1].Select
    Workbooks.Open Filename:=MyFolder & "\" & wb1
    Workbooks(wb1).Activate
    [A1:u60].Select
    Selection.Copy
    Windows("workingmacro.xlsm").Activate
    Sheets("Wells_Check").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    Workbooks(wb1).Close
    
    'Open and copy data from Meta file
    Sheets("Meta").Select
    [A1].Select
    Workbooks.Open Filename:=MyFolder1 & "\" & wb2
    Windows(wb2).Activate
    Sheets(sDay).Select
    
    
    End Sub
    Last edited by nsorresso; 02-27-2019 at 05:38 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Selecting data in an array based on input variables
    By dvess11 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-31-2019, 12:28 PM
  2. Selecting Cells based on Row value and short new sheet based on Cell value
    By John1969 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2016, 03:51 AM
  3. Compare & update unique data between 2 files based on selcted year (through input msgbox)
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2014, 01:35 AM
  4. Selecting Higher/Lower Value based on User Input
    By FTN in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 06-14-2011, 10:31 AM
  5. Selecting Worksheet based on User Input.
    By CJPHX in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-25-2010, 01:58 PM
  6. Selecting Data Based on User Input
    By famousp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2009, 04:16 PM
  7. How to do Input Msgbox to copy select column to sheet 2 ?
    By yannipr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2008, 03:52 PM

Tags for this Thread

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