VBA to find a cell in a specific column that contains text which includes a specific word

Phil Payne

Board Regular
Joined
May 17, 2013
Messages
131
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I'm struggling again and hope our forum can provide a solution!

I need to find a cell in a specific column that contains text which includes a specific word and when found, copy the found cell contents into 5 cells immediately to the right of the found cell.

Solutions found by 'googling' mostly describe searching a single cell or employing a user form that I cannot use or translate into what I need!

My worksheet layout is shown here, I need to find "Total" in column B. Row number 15017 (ID15016) "Site 1 Total" is example of what I wish to achieve! (The '5 cells' C to G are empty at start.)

1ABCDEFGH
1500915008Site 117183493ROOFING WORKS - FELT (INSULATED)W5450Sill boards Ne 200 mm wide28.95__
1501015009Site 117183493 TotalROOFING WORKS - FELT (INSULATED)£9,999.00
1501115010Site 117183503PRELIMSFIXPRSUFIXED PRICE SUB400__
1501215011Site 117183503PRELIMSQ1010Labour only recovery488__
1501315012Site 117183503PRELIMSQ1015Mechanical Plant Hire16085__
1501415013Site 117183503PRELIMSZ0960Provide static guard (night ra701__
1501515014Site 117183503PRELIMSZ0965Provide static guard (week-end384__
1501615015Site 117183503 TotalPRELIMS£8,888.00
1501715016Site 1 TotalSite 1 TotalSite 1 TotalSite 1 TotalSite 1 TotalSite 1 Total£18,887.00
1501815017Site 216562582CARRY OUT LEAD PAINT SURVEYSVAL005CB valuations recovery0.41__
1501915018Site 216562582 TotalCARRY OUT LEAD PAINT SURVEYS£7,777.00
1502015019Site 216651990INSTALL WIRELESS FIRE ALARMFIXPRSUFIXED PRICE SUB35824.57__
1502115020Site 216651990INSTALL WIRELESS FIRE ALARMVAL005CB valuations recovery4.3__
1502215021Site 216651990 TotalINSTALL WIRELESS FIRE ALARM£6,666.00

<tbody>
</tbody>

Thanks very much.

Phil.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello. Phil. Try this:
It's supposed there will be only one word "Total" in column "B" as you'll run the code.


Code:
Sub FindTotal()
 Dim rngT As Range
  Set rngT = ActiveSheet.Columns(2).Find("Total", lookat:=xlPart)
   If Not rngT Is Nothing Then
     ActiveSheet.Cells(rngT.Row, 3).Resize(, 5).Value = rngT.Value
   End If
End Sub
 
Upvote 0
Hi :) Does This code work for you?

Code:
Sub CopyTotal()    Dim i As Long, LastRow As Long
    Dim ws1 As Worksheet


    Set ws1 = ThisWorkbook.Sheets(1)
    
    LastRow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 1 To LastRow
        
        If Range("B" & i).Text Like "*Total*" Then
            Range("B" & i).Copy Destination:=Range("C" & i)
            Range("B" & i).Copy Destination:=Range("D" & i)
            Range("B" & i).Copy Destination:=Range("E" & i)
            Range("B" & i).Copy Destination:=Range("F" & i)
            Range("B" & i).Copy Destination:=Range("G" & i)
        End If
    Next i
End Sub
 
Upvote 0
Hello. Phil. Try this:
It's supposed there will be only one word "Total" in column "B" as you'll run the code.


Code:
Sub FindTotal()
 Dim rngT As Range
  Set rngT = ActiveSheet.Columns(2).Find("Total", lookat:=xlPart)
   If Not rngT Is Nothing Then
     ActiveSheet.Cells(rngT.Row, 3).Resize(, 5).Value = rngT.Value
   End If
End Sub

Thanks very much for the prompt response Osvaldo.
I've chosen to go with Draycuts solution as I can see the column Letters in the code. (Im not very expert at this)
Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,629
Members
449,241
Latest member
NoniJ

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