VBA: Consolidate Selected Worksheet from Multiple Workbooks from OneDrive

datastudent

Board Regular
Joined
Sep 7, 2021
Messages
57
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm new to VBA so I would like to ask some help. I have a folder in OneDrive which has several workbooks. Each workbook has multiple sheets and each of them are different. I want to consolidate each specific sheet in each workbook and put them in a Master File in my computer. But also customize the sheet name when consolidated in the Master file.

This is what I currently have. I don't know if its correct though. Please help!

Master File: Carrier_Rate_Cards.xlsm
Workbook NameWorkbook Sheet NameNew Sheet Name in Master File
Casiguran Rate.xlsxITFSCasRateITFS
Sorsogon Rate.xlsxDomestic RatesSorRateDom
Cawit Rate 01.10.25.xlsxCode ChangesCawitRate
VoxOut National.xlsxInVoxOut
VoxDID MCR.xlsxRangesVoxDID


Sub ConsolidateWorkbooksFromOneDriveWithCustomNamesAndWorksheets()
Dim folderPath As String
Dim fileName As String
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim lastRowSource As Long
Dim lastColSource As Long
Dim lastRowDest As Long
Dim newSheetName As String
Dim sheetList As Object
Dim selectedSheetName As String
Dim sheetName As Variant


folderPath = "C:\Users\iReply\OneDrive\Test"
Set wbDest = Carrier_Rate_Cards.xlsm

Set sheetNamesDict = CreateObject("Scripting.Dictionary")
sheetNamesDict.Add "Casiguran Rate.xlsx", "ITFS"
sheetNamesDict.Add "Sorsogon Rate.xlsx", "Domestic Rates"
sheetNamesDict.Add "Cawit Rate 01.10.25.xlsx", "Code Changes"
sheetNamesDict.Add "VoxOut National.xlsx", "In"
sheetNamesDict.Add "VoxDID MCR.xlsx", "Ranges"

fileName = Dir(folderPath & "*.xlsx")
Do While fileName <> ""
If sheetNamesDict.Exists(fileName) Then
Set wbSource = Workbooks.Open(folderPath & fileName)
targetSheetName = sheetNamesDict(fileName)
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,225,606
Messages
6,185,956
Members
453,333
Latest member
BioCoder84

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