Copy & Paste

detweiler

Board Regular
Joined
Aug 2, 2013
Messages
62
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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
 
Upvote 0
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
 
Upvote 0
How about

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
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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