move cell contents based on presence of a string

G

Guest

Guest
Hi all
Long time lurker, first time poster! Fantastic archive of info on this site but I couldn't quite find enough of an answer to solve my problem. Here it is: 3 columns (a,b, and c) and lots of rows. I need to move down column b searching for a string that ALWAYS starts with text = "dba/". When those characters are found I would like to grab the contents of that cell in column b as well as the contents of the adjacent cell in column c and MOVE them both one cell to the left. So column b contents end up being moved into column a AND column c contents end up being moved to column b. And then resume searching down column b for the next occurence of "dba/". I can use FIND to find "dba/" but I cannot figure out the loop and automated copy of the two cells into their final locations.
many thanks
JB
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi JB


Try

Sub FindIt()
Dim i As Integer
Dim iRow As Integer

iRow = 1
For i = 1 To WorksheetFunction.CountIf(Columns(2), "J**")

iRow = Columns(2).Find(What:="DBA/", After:=Cells(iRow, 2), LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Row

Cells(iRow, 2).Range("A1:B1").Copy Destination:=Cells(iRow, 2).Offset(1, -1)

Next i
End Sub
 
Upvote 0
Oops, yet another typo


Sub FindIt()
Dim i As Integer
Dim iRow As Integer

iRow = 1
For i = 1 To WorksheetFunction.CountIf(Columns(2), "DBA/")

iRow = Columns(2).Find(What:="DBA/", After:=Cells(iRow, 2), LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Row

Cells(iRow, 2).Range("A1:B1").Copy Destination:=Cells(iRow, 2).Offset(1, -1)

Next i
End Sub
_________________
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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