Started By
Message

re: Excel Help - Suggestions

Posted on 4/25/24 at 10:47 pm to
Posted by Chromdome35
NW Arkansas
Member since Nov 2010
6876 posts
Posted on 4/25/24 at 10:47 pm to
To accomplish this, turn to ChatGPT.

I gave ChatGPT the following prompt based on your description.

quote:

In Microsoft Excel, I have 52 workbooks containing 7 tabs. Each workbook represents a week of the year and each tab has the utilization data for a division of our company for that week. The Utilization data is in the same column structure in every tab, the only thing that varies is the number of rows of data. The number of rows of data is dynamic every week on every tab. Write a VBA script that will read the data from each of the tabs in each weeks workbook and combine the data into a single consolidated data table in a separate spreadsheet.


ChatGPT yielded the following VBA Script:

quote:

Sub ConsolidateData()
Dim ws As Worksheet
Dim masterWorkbook As Workbook
Dim dataWorkbook As Workbook
Dim targetSheet As Worksheet
Dim lastRow As Long, lastColumn As Long
Dim dataLastRow As Long
Dim sourceRange As Range
Dim targetRange As Range
Dim folderPath As String
Dim filename As String
Dim weekNum As Integer

' Set the folder path where the weekly workbooks are stored
folderPath = "C:\Path\To\Your\Weekly\Workbooks\" ' Change this to the path where your files are stored

' Create a new workbook
Set masterWorkbook = Workbooks.Add
Set targetSheet = masterWorkbook.Sheets(1)
targetSheet.Name = "Consolidated Data"

' Loop through each workbook
For weekNum = 1 To 52
filename = folderPath & "Week" & weekNum & ".xlsx" ' Adjust the file naming convention as needed

' Open each workbook
Set dataWorkbook = Workbooks.Open(filename)

' Loop through each sheet
For Each ws In dataWorkbook.Sheets
With ws
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
Set sourceRange = .Range(.Cells(1, 1), .Cells(lastRow, lastColumn)) ' Adjust the range as needed

' Find the next empty row in the master sheet
dataLastRow = targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Row + 1

' Set the target range
Set targetRange = targetSheet.Cells(dataLastRow, 1)

' Copy data from source to target
sourceRange.Copy Destination:=targetRange
End With
Next ws

' Close the data workbook without saving
dataWorkbook.Close SaveChanges:=False
Next weekNum

' Save the master workbook
masterWorkbook.SaveAs folderPath & "ConsolidatedData.xlsx"
masterWorkbook.Close SaveChanges:=False

' Inform user
MsgBox "Data consolidation complete!"
End Sub


If you need to add columns to the result for adding date/time, division, etc... to the consolidated data, just tell ChatGPT what you want, where it is in the source data and where you want it to appear in the consolidated data.
This post was edited on 4/25/24 at 10:49 pm
Posted by captainpodnuh
Baton Rouge, LA
Member since Jan 2004
482 posts
Posted on 4/26/24 at 3:06 pm to
Short answer is ChatGPT for all simple software coding. It’s a no brainer. May require minor tweaks but generally it’s solid. A client has been demoing Copilot in their org and is seeing immediate value.
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram