Consolidate data

michelernqm

New Member
Joined
Jun 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi, I am new to VBA and I am wondering if someone could help guide me. I have a xlsm workbook w/ a sheet called "Consolidate" (this is where the data will consolidate to). All files I need to pull data from are in the same folder as the xlsm workbook.
All xlsx files within the folder have a tab called "main".
The macro works for pulling the data I need into the xlsm workbook, but I would like to expand on the macro below. What I am looking for is the data that's being pulled to repeat but with different cells selected and move down the sheet. Cells A1, B2 & C2 are pulled into one row (looping through all the files in the folder)- I want the macro to also pull additional cells from the original source sheets but have it continue to move down the master sheet ("consolidate"). I am not sure how to have the macro pull additional cells- for example cells A22, B23, C23 (from the original sheets) but continue down the master sheet.

If someone has another method or better VBA I am all ears.

Sub Consolidate()

Dim wkbkorigin As Workbook
Dim originsheet As Worksheet
Dim destsheet As Worksheet
Dim ResultRow As Long
Dim Fname As String
Dim RngDest As Range


Set destsheet = ThisWorkbook.Worksheets("Consolidate")
Set RngDest = destsheet.Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0).EntireRow
Fname = Dir(ThisWorkbook.Path & "/*.xlsx")

'loop thropen each file in folder (excluding this one)
Do While Fname <> "" And Fname <> ThisWorkbook.Name

If Fname <> ThisWorkbook.Name Then

Set wkbkorigin = Workbooks.Open(ThisWorkbook.Path & "/" & Fname)
Set originsheet = wkbkorigin.Worksheets("main")

With RngDest
.Cells(1).Value = originsheet.Range("A1").Value
.Cells(2).Value = originsheet.Range("B2").Value
.Cells(3).Value = originsheet.Range("C2").Value

End With

wkbkorigin.Close savechanges:=False 'close current file
Set RngDest = RngDest.Offset(1, 0)

End If

Fname = Dir() 'get next file
Loop
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,606
Messages
6,125,800
Members
449,261
Latest member
Rachel812321

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