import sum to another file

stams

New Member
Joined
Sep 26, 2020
Messages
2
Platform
  1. Windows
Hello all, trying to import some fixed cells from multiple excel files. 1st and 2nd cells are text and numbers and import fine, but my third cell is a sum (H47:H49) and shows the formula when imported (#REF!) I'd like to show the total of the sum.

very new to this VBA scripting, what shoudl I change to get my sum from "H50" Cell?


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:\path_to_files", 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("I6").Copy Destination:=wbDest.Sheets(1).Range("A" & intCounter)

wbResults.Sheets(1).Range("B12").Copy Destination:=wbDest.Sheets(1).Range("B" & intCounter)

wbResults.Sheets(1).Range("H50").Copy Destination:=wbDest.Sheets(1).Range("C" & intCounter)

wbResults.Close SaveChanges:=False
Next lCount
End If
On Error GoTo 0
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
nevermind got it working, if you ever get the same issue, replace the following line:

wbResults.Sheets(1).Range("H50").Copy Destination:=wbDest.Sheets(1).Range("C" & intCounter)
by
wbResults.Sheets(1).Range("H50").Copy
wbDest.Sheets(1).Range("C" & intCounter).PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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