+ Reply to Thread
Results 1 to 8 of 8

VBA code that copies different sheets and paste in one sheet, column by column

Hybrid View

leewk114 VBA code that copies... 08-06-2019, 04:45 PM
MrGes Re: VBA code that copies... 08-06-2019, 04:54 PM
leewk114 Re: VBA code that copies... 08-06-2019, 05:07 PM
MrGes Re: VBA code that copies... 08-06-2019, 05:32 PM
leewk114 Re: VBA code that copies... 08-06-2019, 05:56 PM
Marc L Hi ! Try this ! 08-06-2019, 06:59 PM
leewk114 Re: Hi ! Try this ! 08-06-2019, 07:11 PM
Marc L Thanks for the rep' ! I... 08-06-2019, 07:34 PM
  1. #1
    Registered User
    Join Date
    08-06-2019
    Location
    sacramento
    MS-Off Ver
    365
    Posts
    21

    Unhappy VBA code that copies different sheets and paste in one sheet, column by column

    I am trying to make a code that brings data in multiple sheets and align in one sheet column by column

    This code I have, brings the data and stack it vertically one sheet on top of another sheet

    but I want it to stack horizontally like sheet1 data will be in column A, B, C and and sheet2 data will be in column D, E, F.

    data is already aligned by column i just want the program to stack column by column instead of row by row

    I thought changing last line: Range("A65536").End (xlUp)(2) ---> Range("XFD").End (xlleft)(2)

    but it does not work, here is my code below

    Sub combinesheets()
    
    Dim J As Integer
    
    
    On Error Resume Next
    
    
    Sheets(1).Select
    
    
    Worksheets.Add
    
    
    Sheets(1).Name = "Combined"
    
    
    Sheets(2).Activate
    
    
    Range("A1").EntireRow.Select
    
    
    Selection.Copy Destination:=Sheets(1).Range("A1")
    
    
    For J = 2 To Sheets.Count
    
    
    Sheets(J).Activate
    
    
    Range("A1").Select
    
    
    Selection.CurrentRegion.Select
    
    
    Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
    
    
    Next
    
    
    End Sub
    Attached Files Attached Files
    Last edited by leewk114; 08-06-2019 at 05:07 PM. Reason: attaching examples

  2. #2
    Registered User
    Join Date
    07-21-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA code that copies different sheets and paste in one sheet, column by column

    Hi,
    attach an example file

  3. #3
    Registered User
    Join Date
    08-06-2019
    Location
    sacramento
    MS-Off Ver
    365
    Posts
    21

    Re: VBA code that copies different sheets and paste in one sheet, column by column

    Hi, I just attached an example file

  4. #4
    Registered User
    Join Date
    07-21-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA code that copies different sheets and paste in one sheet, column by column

    Try this code
    Public Sub a()
        Dim Fg As Integer
        Dim lR As Long
        Dim lC As Integer
        NameSheet = "Combined"
        For Each WS In Worksheets
            If WS.Name = NameSheet Then
                MsgBox "The sheet " & NameSheet & " exist!"
                Exit Sub
            End If
        Next
        Sheets.Add
        ActiveSheet.Name = NameSheet
        Sheets(NameSheet).Move Before:=Sheets(1)
        For Fg = 2 To Sheets.Count
            With Sheets(Fg)
                lR = .Cells(Rows.Count, 1).End(xlUp).Row
                lC = .Cells(1, Columns.Count).End(xlToLeft).Column
                .Range(.Cells(1, 1), .Cells(lR, lC)).Copy
                lCx = Sheets("combined").Cells(1, Columns.Count).End(xlToLeft).Column + 1
                If Sheets("combined").Cells(1, 1) = "" Then lCx = 1
                Sheets("combined").Cells(1, lCx).PasteSpecial Paste:=xlValues
            End With
        Next Fg
    End Sub
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-06-2019
    Location
    sacramento
    MS-Off Ver
    365
    Posts
    21

    Re: VBA code that copies different sheets and paste in one sheet, column by column

    oh my god, IT WORKS thank you very much...now i am going to study your code. Thank you very much for your help!

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    As a beginner starter a demonstration working even if sheet Combined already exists & whatever its index position,
    without leaving a blank column for any empty sheet neither using the End function :

    PHP Code: 
    Sub Demo1()
      Const 
    "Combined"
        
    Dim C%, Ws As Worksheet
            C 
    1
        
    If Evaluate("ISREF(" "!A1)"Then
            Sheets
    (N).UsedRange.Clear
            Application
    .Goto Range("!A1"), True
        
    Else
            
    Sheets.Add(Sheets(1)).Name N
        End 
    If
            
    Application.ScreenUpdating False
        
    For Each Ws In Worksheets
            
    If Ws.Name <> N Then
                With Ws
    .UsedRange
                    
    If Not (IsEmpty(.Cells(1)) And .Count 1Then
                       
    .Copy Cells(C)
                        
    + .Columns.Count
                    End 
    If
                
    End With
            End 
    If
        
    Next
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-06-2019 at 07:40 PM. Reason: optimization …

  7. #7
    Registered User
    Join Date
    08-06-2019
    Location
    sacramento
    MS-Off Ver
    365
    Posts
    21

    Re: Hi ! Try this !

    Thank you for your help! I was on this for 2days by myself, I am amazed how you guys are so fast and helpful. I appreciate very much!!!

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Thumbs up

    Thanks for the rep' !

    I just amend the code in case of an existing 'Combined' sheet is not the first one …

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copies of all the sheets if column A contains ...
    By Berna11 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 12-19-2016, 04:25 PM
  2. VBA COde For copy and paste B column of every sheets to new workbook in one sheet
    By Chetan_raghu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2016, 02:22 PM
  3. Replies: 1
    Last Post: 05-30-2015, 04:38 PM
  4. [SOLVED] Need to modify VBA Code that copies multiple sheets to a master sheet
    By AXGirl in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-02-2014, 04:37 PM
  5. [SOLVED] VBA code to combine data from two different sheet columns and paste new sheet and column?
    By Chris* in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2014, 03:15 AM
  6. [SOLVED] need macro that prints sheets listed in column a and the # of copies i want in column b
    By ffxmp0 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2012, 11:22 PM
  7. Macro that copies from multiple sheets to one column
    By favoritepsalm1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2007, 02:33 PM

Tags for this Thread

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