# Copy & Paste

#### detweiler

##### Board Regular
As part of some prep work I have found myself routinely doing, I have to update column J in 6 worksheets by replacing the device or tag id number with the available name which could be in an adjacent cell in columns K through P. I say could be because one or more of the cells could be empty.

I have skulked around the interwebs for pieces of how to do this to frankenvba something together. Having failed miserably, I have come home seeking any help.

What I would like to do is to first locate the device or tag id number in column J, then look for the first cell to the right, limiting the look through column P, with any content and copy it back into the cell to replace the device or tag id number.

Guidance and instruction are, as always, very much appreciated.

### Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

#### rpaulson

##### Well-known Member
try this on a copy of your file>

Code:
``````Sub Replace_j()

For r = 2 To Cells(Rows.Count, "J").End(xlUp).Row

If Cells(r, "J") = "device" Or Cells(r, "J") = "tag id" Then

For c = 16 To 11 Step -1 'loop thru column P thru K in reverse
If Cells(r, c) = "" Then GoTo 88

Cells(r, "J") = Cells(r, c)

88 Next c
99 End If
Next r

End Sub``````

hth,

Ross

#### detweiler

##### Board Regular
Ross,

Thanks. Definitely wouldn't have been able to frankenvba that together!

My bad on this, but did try to see if I could find answer first... for the first If Cells(r, "J"), how do I get it to process only those cells that have numbers in them and not the literal text "device" or "tag id"?

TJ

#### rpaulson

##### Well-known Member
If IsNumeric(Cells(r, "J")) = True Then

#### DanteAmor

##### Well-known Member

Code:
``````Sub Copy_paste()
Dim c As Range, d As String

For Each c In Range("J2", Range("J" & Rows.Count).End(xlUp))
If c.Value Like "*[0-9]*" Then
d = Range("J" & c.Row & ":P" & c.Row).End(xlToRight)
c.Value = IIf(d <> "", d, c)
End If
Next
End Sub``````

#### detweiler

##### Board Regular
Just wanted to thanks again to Rosss ( rpaulson ) and DanteArmor for the assist.

#### DanteAmor

##### Well-known Member

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

### Forum statistics

1,167,943
Messages
5,856,438
Members
431,814
Latest member
qualitypavingstone

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