Forum Discussion
Rachel1950
Jul 24, 2025Brass Contributor
import data from a master file in to other excel files
Hi, i have a master file that i fill in daily with new data that has 5 different business accounts (column k e.g xtr-, bms- etcetera). This file produces a kpi for what's outstanding. New data is add...
Kidd_Ip
Jul 27, 2025MVP
How about this:
Sub ImportFilteredData()
Dim masterWB As Workbook
Dim sourceWS As Worksheet
Dim targetWB As Workbook
Dim targetWS As Worksheet
Dim lastRow As Long, copyRow As Long
Dim i As Long
Dim businessCode As String
Dim sourcePath As String
Dim targetPath As String
' Set paths and business code
sourcePath = "C:\Path\To\MasterFile.xlsx"
targetPath = "C:\Path\To\xtrFile.xlsx"
businessCode = "xtr-"
' Open Master Workbook
Set masterWB = Workbooks.Open(sourcePath)
Set sourceWS = masterWB.Sheets("Sheet1")
lastRow = sourceWS.Cells(sourceWS.Rows.Count, "K").End(xlUp).Row
' Open Target Workbook
Set targetWB = Workbooks.Open(targetPath)
Set targetWS = targetWB.Sheets("Sheet1")
copyRow = targetWS.Cells(targetWS.Rows.Count, "A").End(xlUp).Row + 1
' Loop through master data
For i = 2 To lastRow ' assuming row 1 has headers
If sourceWS.Cells(i, "K").Value = businessCode Then
Dim col As Long
Dim destCol As Long: destCol = 1
' Copy columns A and D-N, excluding formulas
For col = 1 To sourceWS.Columns.Count
If col = 1 Or (col >= 4 And col <= 14) Then
If Not sourceWS.Cells(i, col).HasFormula Then
targetWS.Cells(copyRow, destCol).Value = sourceWS.Cells(i, col).Value
End If
destCol = destCol + 1
End If
Next col
copyRow = copyRow + 1
End If
Next i
' Save & Close both workbooks
targetWB.Save
targetWB.Close
masterWB.Close False
End Sub