Extract data from multiple files

jerk

New Member
Joined
Jul 28, 2020
Messages
4
Office Version
  1. 365
  2. 2019
  3. 2016
Hello
I use a vba script from this forum and i need two modifications
1. i need script to extract data from files but script extract data and write just in one colums one under the other
exemple if i extract data from file1.xlsm what i extract to write in collum A, file2.xlsm write in collum B, files3.xlsm write in collum C etc
2. i need at this script to ignore empty space
example i extract data from a file and in Collum i have 2 lines it extract "r" lines not all from la first empty line ( 2 )

my code
VBA Code:
    Public Sub centralizareMeniu()
    
        Dim folderPath As String
        Dim fileName As String
        Dim destCell As Range, r As Long
        Dim fromWorkbook As Workbook
        
        'Folder containing the workbooks
        
        folderPath = Application.ActiveWorkbook.Path
        If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
        
        With ThisWorkbook.ActiveSheet
            Set destCell = .Cells(.Rows.Count, "A").End(xlUp)
            If Not IsEmpty(destCell.Value) Then Set destCell = destCell.Offset(1)
        End With
        
        'Open file names matching *.xls
        
        fileName = Dir(folderPath & "*NIR*.xlsm")
        r = 0
        Do While fileName <> vbNullString
            Set fromWorkbook = Workbooks.Open(folderPath & fileName)
            destCell.Offset(r).Resize(15, 10).Value = fromWorkbook.Worksheets("db").Range("A1:J15").Value
            r = r + 15

            fromWorkbook.Close savechanges:=False
            DoEvents
            
            'Get next file name
           ' Cells.Replace "#N/A", "", xlWhole
            fileName = Dir
        Loop
        
        MsgBox "Finished"
        
    End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,144,517
Messages
5,724,817
Members
422,580
Latest member
ScotIain76

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
Top