Avatar of Euro5
Euro5
Flag for United States of America asked on

VBA find and move text in workbook

I need to find text
"60200 - Auto" jn column A and cut/paste 1 row down

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Fabrice Lambert

8/22/2022 - Mon
Andrew Porter

This should be close.

Sub FindSomeText()
  If InStr([cell range], "[string you're looking for]")
  Range("[cells your cutting]").Cut Range("[cells your pasting]")
End Sub


Euro5

ASKER
Thanks, Andrew Porter!
I have the following - but I can't figure out the last step to OFFSET one cell down from the Selected cell.


Sub moveutilities()

    Cells.Find(What:="60200 · Auto", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Application.CutCopyMode = False
    Selection.Cut
    Range("A257").Select
    ActiveSheet.Paste
End Sub
Peter Chan

Hi,
See example below:
        Set c1 = Worksheets("Sheet2").Range("A:A").Find("60200 - Auto" )
       
        If Not c1 Is Nothing Then
           'Further do copy here
        End If

Open in new window



This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Euro5

ASKER
Thanks Peter Chan, but not dynamic. I have to do this for each worksheet in workbook and don't know where the text will be.

I thought this would work, but it just moves the 60200-Auto multiple times in the same sheet - rather than moving down 1 row in each sheet!  :)

Sub moveutilities()
    Dim Ws As Excel.Worksheet
    For Each Ws In ThisWorkbook.Worksheets
   
    Cells.Find(What:="60200 · Auto", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Application.CutCopyMode = False
    Selection.Cut
    ActiveCell.Offset(1, 0).Select
    ActiveSheet.Paste
        Next
End Sub
ASKER CERTIFIED SOLUTION
Fabrice Lambert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.