Excel - create vba macro - find cell containing certain word copy cell content paste to another worksheet

Posted on 2006-03-24
Last Modified: 2012-06-27
I would like to search an excel file for a certain word -> for each cell found -> copy that cell's content and paste it in another worksheet.
-> Make a list of the extracted content. (that is 2nd copy and paste will be placed below the 1st extracted cell).

Question by:zaza5586
    1 Comment
    LVL 35

    Accepted Solution

    Hi zaza,

    First off, take a look at a useful find routine made by mdmackillop (also on EE occasionally), should probably do exactly as you need.

    You can also use the following:

    Sub zaza5586()
     Dim WS As Worksheet, nWS As Worksheet, vWhat As String, CLL As Range, FND As Range
     vWhat = InputBox("What are you searching for?")
     If Len(vWhat) = 0 Then Exit Sub
     Application.ScreenUpdating = False
     Set nWS = Sheets.Add
     On Error Resume Next
     nWS.Name = "Search Results"
     On Error GoTo 0
     For Each WS In ActiveWorkbook.Sheets
      If WS.Name <> nWS.Name Then
       Set FND = Nothing
       Set FND = FoundRange(WS.Cells, vWhat)
       If Not FND Is Nothing Then
        For Each CLL In FND.Cells
         With WS.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
          .Value = CLL.Value
          .Offset(0, 1).Value = "'" & WS.Name & "'!" & CLL.Address(0, 0)
         End With
       End If
      End If
     Application.ScreenUpdating = True
    End Sub
    Function FoundRange(ByVal vRG As Range, ByVal vVal) As Range
     Dim FND As Range, FND1 As Range
     Set FND = vRG.Find(vVal, LookIn:=xlValues, LookAt:=xlPart)
     If Not FND Is Nothing Then
      Set FoundRange = FND
      Set FND1 = FND
      Set FND = vRG.FindNext(FND)
      Do Until FND.Address = FND1.Address
       Set FoundRange = Union(FoundRange, FND)
       Set FND = vRG.FindNext(FND)
     End If
    End Function


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
    I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
    This video shows how use content aware, what it’s used for, and when to use it over other tools.
    An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now