+ Reply to Thread
Results 1 to 11 of 11

Merge first column From Multiple Sheets Into One Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    28

    Merge first column From Multiple Sheets Into One Sheet

    I have a excel file containing over 100 sheets and I want to merge whatever data these 100 worksheets have in column A on a new sheet named "Import"

    How can I do this? Have uploaded an attachment
    Attached Files Attached Files
    Last edited by Tomboy; 01-18-2011 at 06:34 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Merge first column From Multiple Sheets Into One Sheet

    see attachment, run macro "test"
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-18-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Merge first column From Multiple Sheets Into One Sheet

    its workin on the raw data that I supplied, thanx, but it not working on the actual data, getting the error message "Run time error 1004" No cells were found.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Merge first column From Multiple Sheets Into One Sheet

    it looks for text and data in column 1 as in example. So the example do not correspond to the real data in terms of data type

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Merge first column From Multiple Sheets Into One Sheet

    I'd use
    Sub snb()
      For Each sh In Sheets
        If sh.Name <> "Result" Then c01 = c01 & "|" & Join(Application.Transpose(sh.UsedRange.Columns(1)), "|")
      Next
    
      Sheets("Result").Cells(1).Resize(UBound(Split(c01, "|"))) = Application.Transpose(Split(Mid(c01, 2), "|"))
    End Sub



  6. #6
    Registered User
    Join Date
    01-18-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Merge first column From Multiple Sheets Into One Sheet

    Hi, thanx mate, this is producing the desired result with the actual data.

    Cheers, if u can explain the code, it wud be gr8 for me.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Merge first column From Multiple Sheets Into One Sheet

    For Each sh In Sheets
    --
    Next

    'Walk' through all sheets in the workbook
    If sh.Name <> "Result" Then
    If the name of the sheet isn't 'Result' then do:
    sh.UsedRange.Columns(1)
    determine the area that has been used (values, formulae, etc) in the sheet; take column 1 of that area.
    Application.Transpose(..)
    convert that first column into a 1-dimensional array
    join(...,"|")
    convert that 1-dimensional array to a textstring with a pipeline "|" as separator
    c01 = c01 & "|" &
    add this textstring to the variable c01 in which all previous textstrings have been stored.

    Sheets("Result").Cells(1).Resize(UBound(Split(c01, "|")))
    Select a range in sheet 'Result' that has the same size as the number of separate values in textstring c01
    split(c01,"|")
    Convert the textstring c01 into a 1-dimensional array
    application.transpose(..)convert the 1-dimensional array to a vertical one.

    And I prefer
    If you can explain the code, it would be great for me
    to
    if u can explain the code, it wud be gr8 for me.
    Last edited by snb; 01-19-2011 at 11:30 AM.

  8. #8
    Registered User
    Join Date
    01-18-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Merge first column From Multiple Sheets Into One Sheet

    Quote Originally Posted by snb View Post
    For Each sh In Sheets
    --
    Next

    'Walk' through all sheets in the workbook
    If sh.Name <> "Result" Then
    If the name of the sheet isn't 'Result' then do:
    sh.UsedRange.Columns(1)
    determine the area that has been used (values, formulae, etc) in the sheet; take column 1 of that area.
    Application.Transpose(..)
    convert that first column into a 1-dimensional array
    join(...,"|")
    convert that 1-dimensional array to a textstring with a pipeline "|" as separator
    c01 = c01 & "|" &
    add this textstring to the variable c01 in which all previous textstrings have been stored.

    Sheets("Result").Cells(1).Resize(UBound(Split(c01, "|")))
    Select a range in sheet 'Result' that has the same size as the number of separate values in textstring c01
    split(c01,"|")
    Convert the textstring c01 into a 1-dimensional array
    application.transpose(..)convert the 1-dimensional array to a vertical one.

    And I prefer
    If you can explain the code, it would be great for me
    to
    if u can explain the code, it wud be gr8 for me.
    Hi,

    Thanks for the detailed explanation. Noted, will avoid using slangs in conversation. Can you suggest what all changes I should make if the data that I'm tryin to grab/consolidate is on a seperate excel file "RawData.xls". This works well but it also fetches the data from the sheets in the workbook that are not part of this exercise.

    Also, seen your message that you would like to review my curriculum. Can you messgae me your email address so that I can forward it.

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: Merge first column From Multiple Sheets Into One Sheet

    Quote Originally Posted by snb View Post
    [COLOR="Blue"] And I prefer
    If you can explain the code, it would be great for me
    to
    if u can explain the code, it wud be gr8 for me.
    If u can xplain d code, it wud B gr8 4 me.
    Never use Merged Cells in Excel

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Merge first column From Multiple Sheets Into One Sheet

    Although you are 'hijacking', you'll find the answers on concatenating row, column and range here

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1