currently the code below will copy two spreadsheets into the macro sheet.
Problem: I want to use Excel cells to specify a file path (from cell A1, A2 or wherever), a sheet name (from cell B1, B2), and a corresponding specified cell range (in cells C1, C2) instead of having to browse to each file with the Application.
Option Explicit
Sub Sample()
Dim wb1 As Workbook: Set wb1 = ThisWorkbook
Dim wb2 As Workbook
Dim i As Long
Dim wsNew As Worksheet
Dim ws As Worksheet: Set ws = wb1.Sheets("Sheet1")
Dim LastRow
Dim sheetName As String
Dim rangeStart As String
Dim rangeEnd As String
Dim ws2 As Worksheet
Dim CellValueToCopy As String
'declare and set your worksheet with your filenames
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'get the last row with data by finding the last item in Column A
For i = 2 To LastRow 'loop from Row 2 to Last in Sheet1 of this workbook
Set wb2 = Workbooks.Open(ws.Cells(i, "A")) 'open the file stored in Column A of Sheet1 of this workbook
sheetName = ws.Cells(i, "B")
rangeStart = ws.Cells(i, "C")
rangeEnd = ws.Cells(i, "D")
'wb2.Sheets(ws.Cells(i, "B").Value).range(ws.Cells(i, "C").Value).Copy
Set ws2 = wb2.Worksheets(sheetName)
wb1.Sheets.Add
wb1.ActiveSheet.Name = sheetName + "_added"
' the below is a proof of concept to copy the values
' loop through the range rather than just one cell to get the final copy
CellValueToCopy = ws2.Cells(1, 1)
wb1.ActiveSheet.Cells(1, 1) = CellValueToCopy
' close workbook and reset variables
wb2.Close SaveChanges:=False
Set wb2 = Nothing
Set wsNew = Nothing
Set ws2 = Nothing
Next i
End Sub
Workbooks.Open (Range("A1").Value)
. Of course you need to qualify the range with a sheet and a workbook as you are working with multiple files. The same principle applies to sheets etc. – SJR