+ Reply to Thread
Results 1 to 4 of 4

If row contains a string copy that row and add string text to cells in it.

Hybrid View

  1. #1
    Registered User
    Join Date
    01-04-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    11

    If row contains a string copy that row and add string text to cells in it.

    So heres what I need to do. Search a column to see if it contains a string say "ItemA" anywhere in that cell. If it does then copy that row into a new row and add that string to several cells in the new row.

    Case "ItemA"
            Copy String to the end of record
            Get column A of row I just copied and add "ItemA" to the begining
    Thnx in advance for the help!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: If row contains a string copy that row and add string text to cells in it.

    An example workbook would help.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-04-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: If row contains a string copy that row and add string text to cells in it.

    Sure

    
    Original Row
                       A                                         B 
    This text contains the word Dogs                        Cats, Birds
    
    Pasted Row
                       A                                         B
    This text contains the word Dogs                    Dogs, Cats, Birds
    So basically do the above.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: If row contains a string copy that row and add string text to cells in it.

    adapt this regular
    Sub ptestp()
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim FoundOne As Range, LookInR As Range, LookForR As Range, c As Range
        Dim nr3    As Long, fAddress
        Application.ScreenUpdating = False
        Set ws1 = Sheets("Sheet7")
        Set ws2 = Sheets("Sheet8")
    
        Set LookInR = ws1.Range("A2:A10")
        Set LookForR = Range(ws2.Range("A2"), ws2.Range("A" & Rows.Count).End(xlUp))
    
        For Each c In LookForR
            With LookInR
                Set FoundOne = .Find(What:=c, lookat:=xlPart)
             
                If Not FoundOne Is Nothing Then
                    fAddress = FoundOne.Address
                  
                    Do
                     
                    FoundOne.Offset(0, 1).Value = c.Value & IIf(FoundOne.Offset(0, 1) <> "", ", ", " ") & FoundOne.Offset(0, 1)
                          Set FoundOne = .FindNext(After:=FoundOne)
                    Loop While FoundOne.Address <> fAddress
                End If
            End With
        Next c
        Set ws1 = Nothing
        Set ws2 = Nothing
        Set LookInR = Nothing: Set LookForR = Nothing
        Application.ScreenUpdating = True
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ Reply to Thread

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