# Find cells with a given value and copy the two cells to the left...

#### Phil Smith

##### Active Member
On my worksheet "Roster", I need to find which cells in columns I, M, Q, U & Y contain "SP".

At the moment I am looping through I2:I71, M2:M71, Q2:Q71, U2:U71 and Y2:Y71.

For example, the first cell that contains "SP" is I9. I would then need to copy G9:H9 and paste those values to cells AG4:AH4 on worksheet "Data".

The next instance would then be pasted to AG5:AH5 and so on.

Is there a quicker way rather than looping through each of the 70 rows in each column? Once I have that syntax, I think I can work the rest out.

### Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Sub Solution()
On Error Resume Next
r=4
With Sheets("Roster").Range("I2:I71,M2:M71,Q2:Q71,U2:U71,Y2:Y71")
Set cel=.Find("SP",Lookat:=xlwhole)
Set First=cel
Do
If err.number<>0 then exit sub
cel.offset(,-2).resize(1,2).copy Sheet("Data").cells(rw,33)
rw=rw+1
Set cel=.Findnext(after:=cel)
Loop
End With
End Sub

Thanks for your solution, however I had to change r=4 to rw=4 to get it to work.

It does what I need with the exception that it copies the formatting as well, whereas I just need the values.

Can that be achieved?

The r=4 was a typo, sorry. Yes, it should be rw=4.
The solution is change
cel.offset(,-2).resize(1,2).copy Sheets("Data").cells(rw,33)

to

cel.offset(,-2).resize(1,2).copy
Sheets("Data").Cells(rw,33).Pastespecial xlpastevalues

Replies
3
Views
180
Replies
2
Views
387
Replies
8
Views
514
Replies
0
Views
117
Replies
2
Views
129

1,203,610
Messages
6,056,296
Members
444,855
Latest member

### 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.

### Which adblocker are you using?

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

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