Hi everybody! I'm trying to create a macro that can take data from 2 different worksheets and combine it into one. I have everything working fine currently with one caveat, the data in both of the source workbooks needs to be in the 1st sheet, and I can't figure out how to change that.
One of the workbooks I need to pull from comes with the data I need on the 2nd sheet (named "Direct Payroll Adjustments") . I can of course go into that file and just remove the other sheets before I begin but that kind of defeats the purpose of having a macro. Here's a snippet of the code with the problem-
It's the line **"OpenBook.Sheets(1).Range("A1").Select"** that seems to be the problem. I've tried replacing the (1) with the name of the sheet in quotes, and a number 2(it's the 2nd sheet in the file) but neither work. I've also tried using OpenBook.Worksheets, that doesn't work either. Anyone know what I'm missing here? Thanks!
One of the workbooks I need to pull from comes with the data I need on the 2nd sheet (named "Direct Payroll Adjustments") . I can of course go into that file and just remove the other sheets before I begin but that kind of defeats the purpose of having a macro. Here's a snippet of the code with the problem-
Excel Formula:
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Sheets.Add.Name = "Direct"
FileToOpen = Application.GetOpenFilename(Title:="Browse for your Direct Payroll Adjustments file", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ThisWorkbook.Worksheets("Direct").Range("A1").PasteSpecial xlPasteValues
OpenBook.Close False
It's the line **"OpenBook.Sheets(1).Range("A1").Select"** that seems to be the problem. I've tried replacing the (1) with the name of the sheet in quotes, and a number 2(it's the 2nd sheet in the file) but neither work. I've also tried using OpenBook.Worksheets, that doesn't work either. Anyone know what I'm missing here? Thanks!