Replacing data in one cell with second name found in another cell

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings,
I'm hoping someone might be able to figure out how to replace a three letter acronym in one cell with the second acronym found in another through VBA. In the example I'm looking to replace BGR found in Column G with LAX only (LAX) found in Column N. There will be no dashes nor space when LAX replaces BGR. This would run true for the entire worksheet "72 Hr" worksheet. LAX is just an example there can be thousands of different three letter codes found is the second code in Column N. If there is no second three letter code then just ignore. In addition, YQX is the only other code in Column G I would like this process to work for. This has to be accomplished for the next VBA I have is to delete all Columns including Column N and conduct a VLOOKup through VBA. Both of those I already have completed. Thank you,
downline station code.JPG
 

Attachments

  • downline station code.JPG
    downline station code.JPG
    17.3 KB · Views: 8
I hope this works.
A visual example causes in most cases additional clarification (y)
See if this works for you ...

VBA Code:
Public Sub Livin404()

    Dim oWs As Worksheet, rng As Range, c As Range, s As String

    Set oWs = ThisWorkbook.Sheets("72 hr")
    Set rng = Application.Intersect(oWs.[F:F], oWs.UsedRange)

    For Each c In rng
        On Error Resume Next
        s = Mid(c.Offset(0, 5), InStr(c.Offset(0, 5), c.Value) - 4, 3)
        On Error GoTo 0
        If Len(s) > 0 Then
            c.Value = s
        End If
    Next c
End Sub
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Thank you, it does indeed accomplish the change, but for everything. I've been looking where I can add
VBA Code:
If CBool(InStr("|BGR|YQX|", "|" & c.Value & "|"))
Then in the VBA to look only for entries with BGR and YQX. Thank you,
 
Upvote 0
You are welcome and thanks for the feedback.
The way in which data to be compared with each other is offered or made available determines the chosen approach within the VBA code.
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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