+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    01-11-2010
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Exclamation code to find, copy and paste until find new, then repeat

    Hello all of you genius programmers!!! I need help with a vba macro code.

    I'm looking for a code that can do the following:

    1 - Search down column A for " / Add New" (that's space slash space Add space New)
    2 - For every instance of " / Add New" in Column A, copy that cell and paste it in Column B to the right.
    3 - Continue to paste down Column B until another " / Add New" is found in Column A.
    4 - When another " / Add New" is found, I need the above actions repeated down the entire column.

    If " / Add New" is not searchable because of the slash, I can find/replace it with something like "elephant" or another word that wouldn't be found anywhere else in the column.

    I attached a sample of the file I'm working with. Thanks for any help you can give!
    Attached Files Attached Files

  2. #2
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: code to find, copy and paste until find new, then repeat

    Hi

    A few small issues:
    1) I can't use your sample because it is .xlsx. If you could add one for excel 03 (just .xls) it'd be more helpful.
    2) Based upon your direction, here is the code. It seems strange to me that column B will continue to have the same cells posted for multiple rows, but if this code works, then there is no need for a more detailed explanation.

    Code:
    Public Sub siddharthariver()
    
    Dim lngLastRow As Long
    Dim blnMarker As Boolean
    
    lngLastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    blnMarker = False
    
    For a = 1 To lngLastRow 'Change 1 to the first row you want to search
        If InStr(ActiveSheet.Cells(a, 1), " / Add New") > 0 Then
            Cells(a, 1).Copy
            blnMarker = True
        End If
        If blnMarker = True Then
            Cells(a, 2).PasteSpecial xlPasteAll
        End If
    Next a
    
    Application.CutCopyMode = False
    
    End Sub
    If this isn't what you wanted, explain how it should be different.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    612

    Re: code to find, copy and paste until find new, then repeat

    Seems like your instructions are slightly off. If I understand this correctly, the first time / Add New is encountered, the rest of column A will be copied to column B. Maybe you need some other delimiter to terminate the copy.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0