+ Reply to Thread
Results 1 to 11 of 11

copy till last used row of a column and paste it into another column of another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-01-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    copy till last used row of a column and paste it into another column of another sheet

    Every week I get data with random number of rows and I need to rearrange those data in certain order so it can accommodate with our system.

    I have attached spreadsheet and would appreciate your assistance with macro to address following issue

    1. need to find last used row and copy column I on sheet("internal") and paste to A2 in sheet("Int-SendOut")
    2. need to find last used row and copy column H on sheet ("Internal") and paste to B2 in sheet("Int-SendOut")
    3. need to find last used row and copy column C on sheet("Internal") and paste to C2 in sheet(Int-Sendout")

    I am wondering what would be vba code to achieve the result based on last used row.

    Thank you very much in advance for your assistance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,568

    Re: copy till last used row of a column and paste it into another column of another sheet

    Hi there,

    Try this:

    Option Explicit
    Sub Macro1()
        
        Sheets("Int-SendOut").Range("A2").Value = Sheets("Internal").Range("I" & Rows.Count).End(xlUp).Value
        Sheets("Int-SendOut").Range("B2").Value = Sheets("Internal").Range("H" & Rows.Count).End(xlUp).Value
        Sheets("Int-SendOut").Range("C2").Value = Sheets("Internal").Range("C" & Rows.Count).End(xlUp).Value
    
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    01-01-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: copy till last used row of a column and paste it into another column of another sheet

    Hi Robert,

    Thanks. I use the above code but it is only returning value on row 2 of sheets("Int-SendOut"). Is there any way we can get all data till last used row from sheets("Internal") and have them pasted on sheets("Int-SendOut")

    Kind regards

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,568

    Re: copy till last used row of a column and paste it into another column of another sheet

    Oh, OK. Try this:

    Option Explicit
    Sub Macro2()
    
        Const lngStartRow As Long = 2 'Starting (static) row number for the data. Change to suit (if necessary).
    
        Dim lngMyRow As Long
        Dim varMyCols As Variant
        Dim strMyCols() As String
        
        Application.ScreenUpdating = False
        
        For Each varMyCols In Array("I-A", "H-B", "C-C") '<= Columns to be copied from - to
        
            strMyCols() = Split(CStr(varMyCols), "-")
            
            lngMyRow = Sheets("Internal").Range(strMyCols(0) & Rows.Count).End(xlUp).Row
        
            Sheets("Internal").Range(strMyCols(0) & lngStartRow & ":" & strMyCols(0) & lngMyRow).Copy Destination:=Sheets("Int-SendOut").Range(strMyCols(1) & lngStartRow)
            
        Next varMyCols
        
        Application.ScreenUpdating = True
    
    End Sub
    Regards,

    Robert

  5. #5
    Registered User
    Join Date
    01-01-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: copy till last used row of a column and paste it into another column of another sheet

    Thank you Robert. Such a nice and perfect code I would have never learnt on my own. I was never aware that we can use copy paste array as you have used. Much appreciated your time and effort.

    Kind regards

  6. #6
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: copy till last used row of a column and paste it into another column of another sheet

    hii

    Try this ...

    Sub copytlllst()
        Dim lst As Long
        Dim lst2 As Long
        Dim lst3 As Long
        Dim intr As Worksheet
        Dim insnot As Worksheet
        Set intr = Worksheets("Internal")
        Set insnot = Worksheets("Int-SendOut")
        With intr
            lst = .Cells(.Rows.Count, "I").End(xlUp).Row
            lst2 = .Cells(.Rows.Count, "H").End(xlUp).Row
            lst3 = .Cells(.Rows.Count, "C").End(xlUp).Row
        End With
        Worksheets("Internal").Select
            Range("I2:I" & lst).Select
            Selection.Copy
        Worksheets("Int-SendOut").Select
        With insnot
            Range("A2").Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        End With
        Worksheets("Internal").Select
            Range("H2:H" & lst2).Select
            Selection.Copy
        Worksheets("Int-SendOut").Select
        With insnot
            Range("B2").Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        End With
        Worksheets("Internal").Select
            Range("C2:C" & lst).Select
            Selection.Copy
        Worksheets("Int-SendOut").Select
        With insnot
            Range("C2").Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        End With
    End Sub
    Don`t care, take care...

    Regards,
    Mangesh

  7. #7
    Registered User
    Join Date
    01-01-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: copy till last used row of a column and paste it into another column of another sheet

    Thank you Mangesh for your time and effort. I have used Robert's code as it is short and sweet.

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,568

    Re: copy till last used row of a column and paste it into another column of another sheet

    Thank you Robert. Such a nice and perfect code I would have never learnt on my own. I was never aware that we can use copy paste array as you have used. Much appreciated your time and effort.
    You're welcome. Always extra happy to help a fellow Aussie

  9. #9
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: copy till last used row of a column and paste it into another column of another sheet

    Hii Trebor76,
    What is this coding nice ...

    Let me know about
    varMyCols In Array("I-A", "H-B", "C-C")

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,568

    Re: copy till last used row of a column and paste it into another column of another sheet

    Hi Trebor76,
    What is this coding nice ...

    Let me know about
    varMyCols In Array("I-A", "H-B", "C-C")
    These are the columns the data is being copied from and to. For instance, column I to column A fro the first block. The varMyCols variable picks up each set of columns which are then split by the minus symbol "-" in the strMyCols array.

    HTH

    Robert

  11. #11
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: copy till last used row of a column and paste it into another column of another sheet

    Quit hard because I am beginner .... Thanks...

+ 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. Replies: 1
    Last Post: 05-30-2015, 04:38 PM
  2. [SOLVED] Macro to copy and paste only unique values from one column to another column in same sheet
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2014, 05:44 AM
  3. copy column and it's row value till column blank found
    By nareshkt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2013, 03:20 AM
  4. Copy entire selected column to next columns till last column
    By siroos12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2013, 05:20 AM
  5. Copy Paste and Loop till last column with data
    By eirumba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2011, 07:23 AM
  6. Copy and Paste Multiple Cells in the same row till last Last Column
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2010, 03:40 PM
  7. Copy and Paste till last Last Column
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2010, 05:43 PM

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