Results 1 to 7 of 7

Thread: VBA Macro To Find Specific Text And Insert Text Few Rows Below

Threaded View

Flupsie VBA Macro To Find Specific... 08-09-2014, 02:44 PM
snb Sample Data ???? 08-09-2014, 04:33 PM
Ingolf Cross post ... 08-09-2014, 06:08 PM
Flupsie Have managed to sort out the... 08-09-2014, 06:10 PM
snb I don't like crossposts, nor... 08-09-2014, 11:54 PM
bakerman Flupsie, Please read... 08-11-2014, 06:45 AM
Flupsie My apologies for not showing... 08-11-2014, 05:41 PM
Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0

    VBA Macro To Find Specific Text And Insert Text Few Rows Below

    I have a workbook with several sheets and want to find "DEPR-GENERATORS" in Col B and insert "DEPR in front on the text from one row below to 5 rows below

    This must exclude sheets "Data", "Accounts", "TB"

    The macro is only affecting the active sheet

    When running the macro the text is inserted for eg DEPRDEPRDEPRDEPRDEPRDEPRDEPRDEPRDEPRDEPRDEPR-COMPUTER EQUIP

    See Sample data



    Code:
    Sub find_Dep()
     Dim Sh As Worksheet
        Dim lr As Long
       For Each Sh In ActiveWorkbook.Worksheets
           Select Case Sh.Name
                Case "Data", "Accounts", "TB"
                Case Else
    
           
                
                With Sh
                    lr = .Cells(.Rows.Count, "B").End(xlUp).Row
                 Cells.Find(What:="DEPR-GENERATORS", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
                    '.Range("B1:B" & lr).Resize(5).Replace What:="   ", Replacement:="DEPR", LookAt:=xlPart
            For i = 1 To 5
                ActiveCell.Offset(i, 1) = "DEPR" & Trim(ActiveCell.Offset(i))
            Next
    End With
    
     End Select
    Next Sh
    
    End Sub
    Your assistance in correcting the code is much appreciated
    Last edited by Flupsie; 08-09-2014 at 02:49 PM.

Similar Threads

  1. Replies: 7
    Last Post: 03-11-2014, 05:38 PM
  2. VBA To Extract Certain Rows From A Text File
    By Bogdan in forum Excel Help
    Replies: 4
    Last Post: 08-31-2013, 06:57 PM
  3. Replies: 7
    Last Post: 08-29-2013, 12:01 PM
  4. Replies: 6
    Last Post: 06-01-2013, 03:24 PM
  5. Replies: 3
    Last Post: 06-01-2013, 11:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •