Hi All
Very new to this.
But I have many workbooks within a folder and I am desperately trying to use a Macro to copy different cells from sheets within the workbooks and paste them into a Master Workbook.
However, the nearest code I could find (see below) only pastes the cells as they are in the sheets they are copied from. Some of the cells are formulas, so in the Master Workbook it does not copy the value of these cells, which is what I need it to do. Any suggestions would be a great help.
Sub CreateList()
Dim iFilesNum As Integer
Dim intCounter As Integer
Dim lCount As Long
Dim recMyFiles() As FoundFileInfo
Dim wbResults As Workbook
Dim wbDest As Workbook
Dim blFilesFound As Boolean
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbDest = ThisWorkbook
intCounter = -1
blFilesFound = FindFiles("C:\Users\MyDoc\", recMyFiles, iFilesNum, "*.xls*", True)
If blFilesFound Then
intCounter = intCounter + 1
For lCount = 1 To iFilesNum 'Loop through all
intCounter = intCounter + 1
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(fileName:=recMyFiles(lCount).sPath & recMyFiles(lCount).sName, UpdateLinks:=0)
wbResults.Sheets(1).Range("b14").Copy Destination:=wbDest.Sheets("Sheet1").Range("a" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("e36").Copy Destination:=wbDest.Sheets("Sheet1").Range("b" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("c37").Copy Destination:=wbDest.Sheets("Sheet1").Range("c" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("n37").Copy Destination:=wbDest.Sheets("Sheet1").Range("d" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("d39").Copy Destination:=wbDest.Sheets("Sheet1").Range("e" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("g45").Copy Destination:=wbDest.Sheets("Sheet1").Range("f" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("h32").Copy Destination:=wbDest.Sheets("Sheet1").Range("g" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("j32").Copy Destination:=wbDest.Sheets("Sheet1").Range("h" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("l32").Copy Destination:=wbDest.Sheets("Sheet1").Range("i" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("m32").Copy Destination:=wbDest.Sheets("Sheet1").Range("j" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("n32").Copy Destination:=wbDest.Sheets("Sheet1").Range("k" & intCounter)
intCounter = intCounter
wbResults.Close SaveChanges:=False
Next lCount
End If
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Very new to this.
But I have many workbooks within a folder and I am desperately trying to use a Macro to copy different cells from sheets within the workbooks and paste them into a Master Workbook.
However, the nearest code I could find (see below) only pastes the cells as they are in the sheets they are copied from. Some of the cells are formulas, so in the Master Workbook it does not copy the value of these cells, which is what I need it to do. Any suggestions would be a great help.
Sub CreateList()
Dim iFilesNum As Integer
Dim intCounter As Integer
Dim lCount As Long
Dim recMyFiles() As FoundFileInfo
Dim wbResults As Workbook
Dim wbDest As Workbook
Dim blFilesFound As Boolean
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbDest = ThisWorkbook
intCounter = -1
blFilesFound = FindFiles("C:\Users\MyDoc\", recMyFiles, iFilesNum, "*.xls*", True)
If blFilesFound Then
intCounter = intCounter + 1
For lCount = 1 To iFilesNum 'Loop through all
intCounter = intCounter + 1
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(fileName:=recMyFiles(lCount).sPath & recMyFiles(lCount).sName, UpdateLinks:=0)
wbResults.Sheets(1).Range("b14").Copy Destination:=wbDest.Sheets("Sheet1").Range("a" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("e36").Copy Destination:=wbDest.Sheets("Sheet1").Range("b" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("c37").Copy Destination:=wbDest.Sheets("Sheet1").Range("c" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("n37").Copy Destination:=wbDest.Sheets("Sheet1").Range("d" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("d39").Copy Destination:=wbDest.Sheets("Sheet1").Range("e" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("g45").Copy Destination:=wbDest.Sheets("Sheet1").Range("f" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("h32").Copy Destination:=wbDest.Sheets("Sheet1").Range("g" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("j32").Copy Destination:=wbDest.Sheets("Sheet1").Range("h" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("l32").Copy Destination:=wbDest.Sheets("Sheet1").Range("i" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("m32").Copy Destination:=wbDest.Sheets("Sheet1").Range("j" & intCounter)
intCounter = intCounter
wbResults.Sheets(1).Range("n32").Copy Destination:=wbDest.Sheets("Sheet1").Range("k" & intCounter)
intCounter = intCounter
wbResults.Close SaveChanges:=False
Next lCount
End If
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub