+ Reply to Thread
Results 1 to 15 of 15

copy rows to table on another sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    copy rows to table on another sheet

    I use this vba below to copy information from one sheet to another which works well, but i would like it to look down from row 52 until it meets a blank row. i know its something like

    ActiveCell.Offset(1, 0).Select
    Loop Until IsEmpty(ActiveCell) = True

    but i am unsure how to adapt it

    Formula: copy to clipboard
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet

    Set copySheet = Worksheets("Consultant Utilisation")
    Set pasteSheet = Worksheets("Consultant Trends")

    copySheet.Range("d52:y52").copy
    pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: copy rows to table on another sheet

    Replace this line

    pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    With

    With pasteSheet
        .Range("A52", .Cells(52, "A").End(xlDown)).PasteSpecial xlPasteAll
    End With


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    will this still copy d to y columns as well ?

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: copy rows to table on another sheet

    Yes surely try it...

  5. #5
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    i changed my code to say
    Formula: copy to clipboard
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet

    Set copySheet = Worksheets("Consultant Utilisation")
    Set pasteSheet = Worksheets("Consultant Trends")

    copySheet.Range("aa3:ad3").copy

    With pasteSheet
    .Range("Aa3", .Cells(3, "A").End(xlDown)).PasteSpecial xlPasteAll
    End With

    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub



    but it only pulled the first row off still, did i do something wrong ?

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: copy rows to table on another sheet

    Try this...

    Private Sub CommandButton1_Click()
    Dim copySheet As Worksheet, pasteSheet As Worksheet, lRw As Long
    
    Set copySheet = Worksheets("Consultant Utilisation")
    Set pasteSheet = Worksheets("Consultant Trends")
    
    Application.ScreenUpdating = False
    
    lRw = .Cells(3, "A").End(xlDown).Row
    If lRw = Rows.Count Then lRw = 1
    
    For i = 1 To lRw
        copySheet.Range("AA" & 2 + i & ":AD" & 2 + i).Copy
        pasteSheet.Range("AA" & 2 + i & ":AD" & 2 + i).Copy
    Next i
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub

  7. #7
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    what i basically have is information in columns aa, ab, ac and ad on sheet "Consultant Utilisation"... i want each row copied on to the next available row on another sheet labelled "Consultant Trends" until it the row in "Consultant Utilisation" is blank.

    if you need me to upload a sample i will, but i need to anonomise the data there due to the information being from a hospital.. data protection and all that..


    i just edited this due to you putting in a new code above.. i will test that first.

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: copy rows to table on another sheet

    Oopss.. try this...

    Private Sub CommandButton1_Click()
    Dim copySheet As Worksheet, pasteSheet As Worksheet, lRw As Long, lNew As Long
    
    Set copySheet = Worksheets("Consultant Utilisation")
    Set pasteSheet = Worksheets("Consultant Trends")
    
    Application.ScreenUpdating = False
    
    lRw = copySheet.Cells(3, "A").End(xlDown).Row
    If lRw = Rows.Count Then lRw = 1
    
    For i = 1 To lRw
        lNew = pasteSheet.Cells(Rows.Count, "AA").End(xlUp).Row + 1
        copySheet.Range("AA" & 2 + i & ":AD" & 2 + i).Copy
        pasteSheet.Range("AA").PasteSpecial xlPasteAll
    Next i
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub

  9. #9
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    this is my file. ignore the ref errors, its because i anonomised it.... the reason why i want this is because consultant utilisation page gets blanked each week, but i want it copied onto the consultant trends before i use it again
    Attached Files Attached Files
    Last edited by wayneg; 11-26-2013 at 09:56 AM.

  10. #10
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    i got a debug error when running your code sixthsense

  11. #11
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    can anybody else help me as well please.

  12. #12
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    bump bump bump

  13. #13
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    i think i managed to do it myself.. this is what i got.. please have a look and tell me if there is an easier way

    Formula: copy to clipboard
    Private Sub CommandButton1_Click()

    Application.ScreenUpdating = False

    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim xrow As Integer, xcol As Integer


    xrow = 3
    xcol = 27
    xcolab = 28
    xcolac = 29
    xcolad = 30


    Set copySheet = Worksheets("Consultant Utilisation")
    Set pasteSheet = Worksheets("Consultant Trends")

    Do Until Cells(xrow, xcol).Value = ""
    Cells(xrow, xcol).Select
    xrow = xrow + 1

    copySheet.Cells(xrow, xcol).Copy
    pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

    copySheet.Cells(xrow, xcolab).Copy
    pasteSheet.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

    copySheet.Cells(xrow, xcolac).Copy
    pasteSheet.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

    copySheet.Cells(xrow, xcolad).Copy
    pasteSheet.Cells(Rows.Count, 4).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues


    Application.CutCopyMode = False
    Application.ScreenUpdating = True

    Loop

    Cells(xrow - 1, xcol).Select


    End Sub


  14. #14
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: copy rows to table on another sheet

    Try this…

    Private Sub CommandButton1_Click()
    Dim copySheet As Worksheet, pasteSheet As Worksheet, lBlank As Long
    Dim lStRw As Long, iCl As Integer, lEndRw As Long, i As Long
    
    lStRw = 3
    iCl = 27
    
    Set copySheet = Worksheets("Consultant Utilisation")
    Set pasteSheet = Worksheets("Consultant Trends")
    
    Application.ScreenUpdating = False
    
    With copySheet
        lEndRw = .Cells(lStRw, iCl).End(xlDown).Row
        lBlank = pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
        
        .Range(.Cells(lStRw, iCl), .Cells(lEndRw, iCl)).Copy
        pasteSheet.Cells(lBlank, "A").PasteSpecial xlPasteValuesAndNumberFormats
        
        iCl = iCl + 1
        .Range(.Cells(lStRw, iCl), .Cells(lEndRw, iCl)).Copy
        pasteSheet.Cells(lBlank, "F").PasteSpecial xlPasteValuesAndNumberFormats
        
        iCl = iCl + 1
        .Range(.Cells(lStRw, iCl), .Cells(lEndRw, iCl)).Copy
        pasteSheet.Cells(lBlank, "P").PasteSpecial xlPasteValuesAndNumberFormats
    
        iCl = iCl + 1
        .Range(.Cells(lStRw, iCl), .Cells(lEndRw, iCl)).Copy
        pasteSheet.Cells(lBlank, "Q").PasteSpecial xlPasteValuesAndNumberFormats
        ActiveCell.PasteSpecial xlPasteFormats
    End With
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub

  15. #15
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    372

    Re: copy rows to table on another sheet

    Sixthsense, your code worked but it put some random formatting on my copysheet... i think i will stick with what i put in originally, but thank you for your help

+ 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. Dialogue box to search date range of table column, copy relevant rows to report sheet
    By Tim Newton in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-26-2013, 03:10 AM
  2. Copy and paste certain rows of a table to create a new table
    By redhawk87 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2013, 12:37 PM
  3. Replies: 1
    Last Post: 01-07-2013, 12:23 AM
  4. Replies: 0
    Last Post: 09-17-2012, 11:10 AM
  5. Replies: 5
    Last Post: 11-12-2008, 05:44 AM

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