Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

Copy data from two different columns from another sheet.

Latest post Mon, Jan 30 2012 8:17 AM by Alan Hutchins. 3 replies.
  • Thu, Jan 26 2012 11:07 AM

    • Frank1701
    • Top 75 Contributor
    • Joined on Thu, Jan 19 2012
    • New York
    • Posts 10
    • Points 178

    Copy data from two different columns from another sheet.

    Ok my question is how to copy data from one sheet to another.  Is using a macro to place the data in different place I select a good way or should I look at VBA? 

    Sheet one will have the work weeks with employee names in column A and E for the hours.  On the other sheet that has data that is refreshed (from MySQL) at the end of each week A3 and up to A7 that is if all employees report hours, or they could be on vacation.   I will do this each week and create a month version later.

    Attached is a sample of the data.

    • Post Points: 21
  • Fri, Jan 27 2012 3:10 PM In reply to

    • Frank1701
    • Top 75 Contributor
    • Joined on Thu, Jan 19 2012
    • New York
    • Posts 10
    • Points 178

    Re: Copy data from two different columns from another sheet.

    Ok I have figured out a few things.  Still looking how to add a variable for location, not having a hard target location.

    Sub Macro6()
    '
    ' Macro6 Macro
    '

    '
        Sheets("Sheet2").Select
        Range("Table1[Employee]").Select
        Selection.Copy
        Sheets("Sheet1").Select
        Range("A4").Select
        ActiveSheet.Paste
        Sheets("Sheet2").Select
        Range("Table1[Hours_Worked]").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Sheet1").Select
        Range("E4").Select
        ActiveSheet.Paste
        Range("C4:C9").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("A3:F10").Select
        Range("F10").Activate
        Application.CutCopyMode = False
        Range("C3:C9").Select
        Selection.Copy
        Range("E4:E9").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        With Selection
            .HorizontalAlignment = xlRight
            .VerticalAlignment = xlBottom
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("C4:C10").Select
        With Selection
            .HorizontalAlignment = xlRight
            .VerticalAlignment = xlBottom
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("C4:C9").Select
        Selection.Copy
        Range("A4:A9").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlBottom
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
    End Sub

    • Post Points: 21
  • Mon, Jan 30 2012 3:22 AM In reply to

    Re: Copy data from two different columns from another sheet.

    Hi Frank,

    No reason why you can't use what you have to do this. VBA would be a better bet in many regards because it would allow you to check that tha names are the same etc, but this could get very complicated as things get bigger.

    An alternative approach would be to use formulae to get what you want.

    I'll Have a look at it in my lunch break and work something up using formulae for you to look at.

     

     

    • Post Points: 5
  • Mon, Jan 30 2012 8:17 AM In reply to

    Re: Copy data from two different columns from another sheet.

    Frank,

    This is 1 way of doing it without VBA.

     

    HTH

     

    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.