Try:
VBA Code:
Dim sh As String
sh = InputBox("Enter the name of the sheet.")
If sh = "" Then Exit Sub
Do While myFile <> ""
Workbooks.Open Filename:=(myfolder & myFile), UpdateLinks:=0
With ActiveWorkbook.Sheets(sh)
a = .Range("B13").Text
x = .Range("N13").Value
y = .Range("N14").Value
End With
Loop
Thank you! works perfect - Can I ask you a favor ? Can you help me make my code better as I am very new at it. Its working now but I feel it can be cleaned up.
Basically, my sheets looks at the employees timesheet in a folder and gets total time spent (Column N) on each project (column B). As I am using absolute reference, its showing me projects with zero hours.
Do While myFile <> ""
Workbooks.Open Filename:=(myfolder & myFile), UpdateLinks:=0
With ActiveWorkbook.sheets(sh)
a = .Range("B13").Text
x = .Range("N13").Value
b = .Range("B14").Text
y = .Range("N14").Value
c = .Range("B15").Text
d = .Range("N15").Value
e = .Range("B16").Text
f = .Range("N16").Value
g = .Range("B17").Text
h = .Range("N17").Value
k = .Range("B18").Text
l = .Range("N18").Value
m = .Range("B19").Text
n = .Range("N19").Value
z = myFile
End With
ActiveWorkbook.Close SaveChanges:=False
Windows("cook.xltm").Activate
ActiveWorkbook.sheets("cook").Cells(i, 2).Value = a
ActiveWorkbook.sheets("cook").Cells(i, 3).Value = x
ActiveWorkbook.sheets("cook").Cells(i, 4).Value = b
ActiveWorkbook.sheets("cook").Cells(i, 5).Value = y
ActiveWorkbook.sheets("cook").Cells(i, 6).Value = c
ActiveWorkbook.sheets("cook").Cells(i, 7).Value = d
ActiveWorkbook.sheets("cook").Cells(i, 8).Value = e
ActiveWorkbook.sheets("cook").Cells(i, 9).Value = f
ActiveWorkbook.sheets("cook").Cells(i, 10).Value = g
ActiveWorkbook.sheets("cook").Cells(i, 11).Value = h
ActiveWorkbook.sheets("cook").Cells(i, 12).Value = k
ActiveWorkbook.sheets("cook").Cells(i, 13).Value = l
ActiveWorkbook.sheets("cook").Cells(i, 14).Value = m
ActiveWorkbook.sheets("cook").Cells(i, 15).Value = n
ActiveWorkbook.sheets("cook").Cells(i, 18) = z
myFile = Dir
i = i + 1
Loop
Result I am getting -