+ Reply to Thread
Results 1 to 12 of 12

VB Code to copy and paste at certain location

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to copy and paste at certain location

    Hello:

    I have data in Column F:H and Column J:L

    I need a VB Code to perform the following:

    First check 6 occurrence of text string "REPORT END" in column F.
    Once it finds the last 6th "REPORT END"in column F, leave one blank row and then copy the content from column J:L.

    Let me know if you have any questions.

    Thanks

    Riz
    Last edited by rizmomin; 07-19-2014 at 03:18 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to copy and paste at certain location

    Hello Riz,

    Can you provide a before and after example?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste at certain location

    Hi Leith:


    Please find Attached File...

    Let me know if you have any questions.

    Thanks

    Riz
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to copy and paste at certain location

    Hello Riz,

    Will it always be the 6th occurrance of "Report End" or can the macro work from the " bottom up" from the bottom the worksheet and find "Report End"?

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste at certain location

    hi Leith:

    Yes it wil always be after the 6th occurance.

    Or best if we can find the end of data in Column F.

    thanks

    Riz
    Last edited by rizmomin; 07-19-2014 at 04:07 PM.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to copy and paste at certain location

    Hello Riz,

    I have added the macro below to the attached workbook. Let me know if this works for you.

    Sub CopyAndInsert()
    
        Dim EndRow  As Long
        Dim FoundIt As Range
        Dim Rng     As Range
        Dim Wks     As Worksheet
        
            Set Wks = ActiveSheet
            
            EndRow = Wks.Cells(Rows.Count, "F").End(xlUp).Row
            
            Set Rng = Wks.Range("F1:F" & EndRow)
            
            Set FoundIt = Rng.Find("Report End", , xlFormulas, xlWhole, xlByRows, xlPrevious, False, False, False)
            
                If Not FoundIt Is Nothing Then
                    Wks.Range("J2").CurrentRegion.Copy Destination:=FoundIt.Offset(2, 0).CurrentRegion
                End If
            
    End Sub
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste at certain location

    Hi Leith:

    Thanks a lot, seems to work great.
    Riz

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste at certain location

    Hi Leith or others:

    The code works great, however i need some modification.
    Currently it is looking for last "REPORT END", and pasting the data.
    Instead i would like to fix it paste at Row # 600.
    Please modify and let me know.

    Let me know if you have any questions.
    Thanks
    Riz

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to copy and paste at certain location

    Hello Riz,

    The change to the macro is in blue.

    Sub CopyAndInsert()
    
        Dim EndRow  As Long
        Dim FoundIt As Range
        Dim Rng     As Range
        Dim Wks     As Worksheet
        
            Set Wks = ActiveSheet
            
            EndRow = Wks.Cells(Rows.Count, "F").End(xlUp).Row
            
            Set Rng = Wks.Range("F1:F" & EndRow)
            
            Set FoundIt = Rng.Find("Report End", , xlFormulas, xlWhole, xlByRows, xlPrevious, False, False, False)
            
                If Not FoundIt Is Nothing Then
                    Wks.Range("J2").CurrentRegion.Copy Destination:=Range("F600")
                End If
            
    End Sub

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to copy and paste at certain location

    Hello Riz,

    The change to the macro is in blue.

    Sub CopyAndInsert()
    
        Dim EndRow  As Long
        Dim FoundIt As Range
        Dim Rng     As Range
        Dim Wks     As Worksheet
        
            Set Wks = ActiveSheet
            
            EndRow = Wks.Cells(Rows.Count, "F").End(xlUp).Row
            
            Set Rng = Wks.Range("F1:F" & EndRow)
            
            Set FoundIt = Rng.Find("Report End", , xlFormulas, xlWhole, xlByRows, xlPrevious, False, False, False)
            
                If Not FoundIt Is Nothing Then
                    Wks.Range("J2").CurrentRegion.Copy Destination:=Range("F600")
                End If
            
    End Sub

  11. #11
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste at certain location

    Hi Leith:

    Works great.
    Thanks
    Riz

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste at certain location

    Hi Leith:

    Works great.
    Thanks
    Riz

+ 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. Copy a set of cells and paste it to a user-specified location
    By abhinav10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2012, 05:51 PM
  2. VBA Copy-paste values with changing paste location
    By booost in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2012, 10:39 AM
  3. Seach, Copy, select paste location, paste using macros
    By helpdave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2010, 11:36 PM
  4. Copy and Paste to location based on cell value
    By CBron12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-15-2010, 03:02 PM
  5. [SOLVED] Copy/Paste without changing location references
    By Tom in forum Excel General
    Replies: 3
    Last Post: 03-31-2005, 09:06 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