Macro for Values - multiple workbooks

MarkT1

New Member
Joined
Jun 16, 2020
Messages
1
Office Version
  1. 2010
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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Do you want to paste by value?

Change this:

VBA Code:
 wbResults.Sheets(1).Range("b14").Copy Destination:=wbDest.Sheets("Sheet1").Range("a" & intCounter)

to

VBA Code:
 wbResults.Sheets(1).Range("b14").Copy 
wbDest.Sheets("Sheet1").Range("a" & intCounter).PasteSpecial Paste:=xlPasteValues

You need to change every instance of copy/paste.
 
Upvote 0

Forum statistics

Threads
1,224,832
Messages
6,181,231
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top