Look for keywords and copy to another sheet

ceclay

Board Regular
Joined
Dec 4, 2019
Messages
58
Office Version
  1. 2016
Platform
  1. Windows
Would like to ask for help on this code below:

I have the following Keywords:
1. Lopez
2. Antetokounmpo
3. Curry
4. Morris

If any of keyword available then it will copy to another sheet together with the next 2 cell below it.


VBA Code:
Sub Replace18()

  
  Dim sh As Worksheet, Sr As Range, Sf As Range, wA As Variant
  Dim FindWhat As Variant
  
 FindWhat = Array("Lopez", "Antetokounmpo", "Curry", "Gasol", "Morris", "Gordon")

  
  Set sh = Sheets("NBA Outright Paste Here")
  Set Sr = sh.Range("A1:A80000")
  
  ''Points scored by the player - Including Overtime
  sRow = 2
  Set Sf = Sr.Find(FindWhat, , xlValues, xlPart)
  If Not Sf Is Nothing Then
    cell = Sf.Address
    Do
      wA = Sf.Resize(3, 1).Value
      With Sheets("Sheet1")
        .Range("A" & Rows.Count).End(xlUp)(2).Resize(3, 1).Value = wA
        .Range("C" & sRow).Resize(1, 3).Value = Application.Transpose(wA)
        sRow = sRow + 1
      End With
      Set Sf = Sr.FindNext(Sf)
    Loop While Not Sf Is Nothing And Sf.Address <> cell
  End If
  

End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You would need to loop through the array.
VBA Code:
Sub Button1_Click()

    Dim sh As Worksheet
    Dim Sr As Range, Sf As Range
    Dim FindWhat As Variant, wA As Variant

    FindWhat = Array _
               ("Lopez", "Antetokounmpo", "Curry", "Gasol", "Morris", "Gordon")


    Set sh = Sheets("NBA Outright Paste Here")
    
    With sh
        Set Sr = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    End With
    
    sRow = 2

    For i = LBound(FindWhat) To UBound(FindWhat)

        ''Points scored by the player - Including Overtime
        Set Sf = Sr.Find(FindWhat(i), , xlValues, xlPart)
        
        If Not Sf Is Nothing Then
            cell = Sf.Address
            
            Do
                wA = Sf.Resize(3, 1).Value
                
                With Sheets("Sheet1")
                    .Range("A" & Rows.Count).End(xlUp)(2).Resize(3, 1).Value = wA
                    .Range("C" & sRow).Resize(1, 3).Value = Application.Transpose(wA)
                    sRow = sRow + 1
                End With
                
                Set Sf = Sr.FindNext(Sf)
            Loop While Not Sf Is Nothing And Sf.Address <> cell
            
        End If
        
    Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top