VBA to Concatenate across multiple workbooks


New Member
I'm trying to write a VBA that will concatenate the same cell across a whole folder of workbooks.

Each workbook in the file is the same, just a different topic. I have 15 different workbooks, for example I have Lion, Tiger, and Panther. In sheet 3 column D of each of these books I have some text.

I want Cat, my master book, to combine the text for each workbook in column D.

So Cat's Sheet 3 D4 will Concatenate Lion's sheet 3 D4, Tigers sheer 3 D4, and Panthers sheet 3 D4.

I would want to do this across all of sheet 3 column D (from D3 - D40), but I don't need any other column of any other sheet.

I hardly know where to start!! I'd love help, assistance, resources, or bits of code that you might find useful!!


Well-known Member
Hi Tooflychicken,

Welcome to MrExcel!!

Try this (just change the setting of the two variables I marked as 'Change to suit'):

Option Explicit
Sub Macro1()

    Dim strFolder As String
    Dim strExtn As String
    Dim varFileName As Variant
    Dim rngMyCell As Range
    Application.ScreenUpdating = False
    strFolder = "C:\Sxamples\" 'Directory with files. Change to suit.
    If Right(strFolder, 1) <> "\" Then
        strFolder = strFolder & "\"
    End If
    varFileName = Dir(strFolder)
    Do Until Len(varFileName) = 0
        strExtn = Trim(Right(varFileName, Len(varFileName) - InStrRev(varFileName, ".")))
        If strExtn Like "xls*" Then
            For Each rngMyCell In ThisWorkbook.Sheets("Cat").Range("D3:D40") 'Range to be linked. Change to suit.
                If Len(rngMyCell) = 0 Then
                    rngMyCell.Formula = "='" & strFolder & "[" & varFileName & "]Sheet3'!" & rngMyCell.Address
                    rngMyCell.Formula = rngMyCell.Formula & "+'" & strFolder & "[" & varFileName & "]Sheet3'!" & rngMyCell.Address
                End If
            Next rngMyCell
        End If
    varFileName = Dir
    Application.ScreenUpdating = True

End Sub


Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Macro to copy values across rows and transposing them and add the user id
    [FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Hi,[/COLOR][/SIZE][/FONT] [FONT=Times New...