Results 1 to 2 of 2

Copy Rows and Paste Based On Cell Values

Threaded View

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    50

    Copy Rows and Paste Based On Cell Values

    Hi

    I am trying to get my macro to copy rows in another excel workbook and paste them further up the page in order to remove duplicate rows of data. I have three cells in that workbook that use formula to calculate the following:

    AK2 - The number of the row everything below is pasted to
    AK3 - The beginning row number of the selection to be copied
    AK4 - The end row number of the selection to be copied

    What I want is for the macro to select the rows numbers from AK3 throught to AK4 and paste them into the row number of AK2.

    Here is the code I am using:

    Sub Data_Harvester_IIIWay()
        Dim wbk As Workbook
    
        On Error Resume Next
        Set wbk = Workbooks("BC.xlsx")
            Workbooks("BC.xlsx").Sheets("BH3").Rows(Workbooks("BC.xlsx").Sheets("BH3").Range("AK3").Value & ":" & Workbooks("BC.xlsx").Sheets("BH3").Range("AK4").Value).Copy
            Workbooks("BC.xlsx").Sheets("BH3").Range("$A$" & Workbooks("BC.xlsx").Sheets("BH3").Range("AK2").Value).Paste
        On Error GoTo 0
        If wbk Is Nothing Then
        Set wbk = Workbooks.Open("C:\BC\BC.xlsx")
            Workbooks("BC.xlsx").Sheets("BH3").Rows(Workbooks("BC.xlsx").Sheets("BH3").Range("AK3").Value & ":" & Workbooks("BC.xlsx").Sheets("BH3").Range("AK4").Value).Copy
            Workbooks("BC.xlsx").Sheets("BH3").Range("$A$" & Workbooks("BC.xlsx").Sheets("BH3").Range("AK2").Value).Paste
        End If
        Set wkb = Nothing
    End Sub
    When I use this code it highlights the selection and copies it correctly but it does not paste it. No errors appear or anything, it just finishes without pasting the data.

    Any help would be greatly appreciated as I have been tearing my hair out for hours

    Doug
    Last edited by boohah; 11-06-2010 at 08:44 AM. Reason: oops, typed the wrong character in the code tag :)

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