Copy & Paste

detweiler

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

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,143
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
Joined
Aug 2, 2013
Messages
57
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

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
 

detweiler

Board Regular
Joined
Aug 2, 2013
Messages
57
Just wanted to thanks again to Rosss ( rpaulson ) and DanteArmor for the assist.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,505
Messages
5,602,062
Members
414,498
Latest member
jordanmiller7890

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
Top