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
Bookmarks