VBA Code for a Chart that calls data from several excel files in a folder

jamosticker

New Member
Joined
Jul 2, 2018
Messages
1
Problem:
1: I have like 20 excel files in a folder
2: I created another excel file specifically to plot all the data in each of the excel files inside the folder together.
3: What I need to do is to create a vba code for the chart that pulls data from each of the 20 excel files in the folder and plot it together automatically.
Please kindly help with this.
Thanks.

I tried using this code that I got from somewhere but it's not working

"Sub TestLoop()
'Declarations
Dim fileName As Variant
Dim myFilePath As String
Dim myChart As Chart
Dim Wkbk As Variant

myFilePath = "C:\Users\jaoadegbite\Desktop\an"
fileName = Dir(myFilePath)

While fileName <> ""

Debug.Print fileName 'This example will print the file name to the immediate window
Set Wkbk = Workbooks.Open(myFilePath & fileName) 'Open Workbook
Set myChart = ActiveSheet.Shapes.AddChart(xlColumnClustered).Chart 'Add Chart
myChart.SetSourceData Source:=ActiveSheet.Range("A2:A30") 'Set DataSource Range
Wkbk.Close SaveChanges:=True 'Close file and save changes
fileName = Dir 'Set the fileName to the next file

Wend

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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