Hi, can someone please help, I am new to VBA.
I have 22 workbooks, they all contain data in the same format (two sheets pr workbook).
I want to consolidate data from the 22 workbooks into one master workbook.
Old posts in Mr.Excel gave me help here and this works fine using this VBA :
But, now I want the VBA to do the following :
1. Don't copy empty rows from the 22 source files. Both worksheets in the 22 source-files can contain empty rows. If there is data in column A, the row should be copied.
2. Add a new column into master-file that gives the filename the data was copied from. I only need this data inn masterworksheet "Brukere" - so would prefer that the column was in column K
Would appreciate help
I have 22 workbooks, they all contain data in the same format (two sheets pr workbook).
I want to consolidate data from the 22 workbooks into one master workbook.
Old posts in Mr.Excel gave me help here and this works fine using this VBA :
VBA Code:
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
'Folder that contains data
Const strPath As String = "\\nash\PAG003\Dokumenter\Masterfiler\"
ChDir strPath
strExtension = Dir("*.xls*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
'Copy data from all workbooks in the datafolder
.Sheets("Kostsentre").Range("A2:F" & Range("A" & Rows.Count).End(xlUp).Row + 1).Copy wkbDest.Sheets("Koststeder").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Sheets("Brukertilganger").Range("A3:J" & Range("A" & Rows.Count).End(xlUp).Row + 1).Copy wkbDest.Sheets("Brukere").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub
But, now I want the VBA to do the following :
1. Don't copy empty rows from the 22 source files. Both worksheets in the 22 source-files can contain empty rows. If there is data in column A, the row should be copied.
2. Add a new column into master-file that gives the filename the data was copied from. I only need this data inn masterworksheet "Brukere" - so would prefer that the column was in column K
Would appreciate help