+ Reply to Thread
Results 1 to 12 of 12

Macro to Copy Second Column in all sheets to new sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Macro to Copy Second Column in all sheets to new sheet

    hi

    please i need ur help,

    i want a macro to copy second column in all sheets (around 30 sheets in one excel file) to new sheet

    i used the following code

    Public Sub Example()
    Dim rngCopy As Range
    With Sheets("Sheet1")
        Set rngCopy = .Range(.Cells(1,"B"),.Cells(.Rows.Count,"B").End(xlUp))
    End With
    With Sheets("SUMMARY")
        .Cells(1,.Columns.Count).End(xlToLeft).Offset(,1).Resize(rngCopy.Rows.Count).Value = rngCopy.Value
    End With
    End Sub
    but this one will copy second column from specific sheet to specific sheet and will over-write the copied columns, i want to copy second column from all sheets to one new sheet (must be created with macro) with paste as value only.

    and all copied columns in the recently created sheet should be continuously, means

    second column from first sheet
    1
    1
    1
    1
    1
    1

    then

    second column from second sheet
    5
    4
    68
    4
    8
    8
    4
    4

    then

    second column from third sheet
    54
    787
    4645
    13258
    879
    34654


    sorry for the long thread
    many thanks in advance
    Last edited by boss1982; 12-29-2012 at 10:06 AM.

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

    Re: Macro to Copy Second Column in all sheets to new sheet

    hi boss1982, please check attachment, the columns would go one by one, press "Run" button or run code "test"
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet

    hi watersev,

    its exactly same as i want, the result is as follows;

    1	2	3
    2	2	3
    3	2	3
    4	2	3
    5		3
    6		3
    7		3
    8		
    9		
    10		
    11
    lets say that the result;

    1	2	3
    2	2	3
    3	2	3
    4	2	3
    5		3
    6		3
    7		3
    8		
    9		2
    10		2
    11		2
    		2
    		
    		
    		
    		
    	2	
    	2	
    	2	
    	2	
    		
    		
    		
    	2	
    	2	
    	2	
    	2
    means with a lot of blanks;
    one more thing plz, another code please or continue ur same code to let the result as follows;


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    2
    2
    2
    2
    
    2
    2
    2
    2
    
    
    
    2
    2
    2
    2
    3
    3
    3
    3
    3
    3
    3
    
    2
    2
    2
    2
    
    2
    2
    2
    2
    3
    3
    3
    3
    3
    3
    3
    Last edited by boss1982; 12-29-2012 at 11:53 AM.

  4. #4
    Registered User
    Join Date
    12-21-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Macro to Copy Second Column in all sheets to new sheet

    made small changes in the watersev code, this should help
    Sub test()
    
    Dim shcount As Long, lrow As Long, i As Long, rng As Range
    
    Application.ScreenUpdating = 0
    
    shcount = Sheets.Count
    Set newsh = Sheets.Add(after:=Sheets(Sheets.Count))
    
    lrow1 = 1
    For i = 1 To shcount
        With Sheets(i)
            lrow = .Cells(Rows.Count, 2).End(xlUp).Row
            Set rng = .Range(.Cells(1, 2), .Cells(lrow, 2))
        End With
        'n = n + 1
        newsh.Cells(lrow1, 1).Resize(lrow).Value = rng.Value
        lrow1 = lrow1 + lrow
    Next
    
    Application.ScreenUpdating = 1
    
    End Sub
    Hope this helps.
    Kiran

  5. #5
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet

    thank you very much kiran, i know that i asked alot;

    after the code which you gave me (it was perfect), can u please give me continued code to delete all blanks rows then the filled one must be shift to up?

    thanks

  6. #6
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet

    it is ok thanks

    i added

        Columns("A:A").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.EntireRow.Delete
        Range("B6").Select

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

    Re: Macro to Copy Second Column in all sheets to new sheet

    add this before Application.ScreenUpdating = 1 in "test" code:

    On Error Resume Next
    newsh.UsedRange.SpecialCells(xlCellTypeBlanks).EntireRow.Delete

  8. #8
    Registered User
    Join Date
    12-21-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Macro to Copy Second Column in all sheets to new sheet

    Hope your problem solved!

  9. #9
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet

    sure

    thank u all

  10. #10
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet

    hi all

    please i need one more help, how to choose which column will be copied?, if i want for example to copy second column + third and fifth.

    this is the code for second column only;

    Dim shcount As Long, lrow As Long, i As Long, rng As Range
    
    Application.ScreenUpdating = 0
    
    shcount = Sheets.Count
    Set newsh = Sheets.Add(After:=Sheets(Sheets.Count))
    
    lrow1 = 1
    For i = 1 To shcount
        With Sheets(i)
            lrow = .Cells(Rows.Count, 2).End(xlUp).Row
            Set rng = .Range(.Cells(1, 2), .Cells(lrow, 2))
        End With
        'n = n + 1
        newsh.Cells(lrow1, 1).Resize(lrow).Value = rng.Value
        lrow1 = lrow1 + lrow
    Next
    Application.ScreenUpdating = 1
    thanks.

  11. #11
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet

    any one can help plz?

  12. #12
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Macro to Copy Second Column in all sheets to new sheet


+ 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