Forum Discussion

Cygnata's avatar
Cygnata
Copper Contributor
Nov 20, 2025
Solved

Need to replace part of one cell with part of another

I need to take the XXX at the end of the name and replace it with the 005 at the end of the Longitude field. Is there any way to do this except manually? There's over 2000 to fix. Thanks.

WreckIDNameNationalityTypePropulsionCause LostYear°Year†WeightLatitudeDecimal LatitudeLongitudeDecimal Longitude
664?40°35'XXXN˜074°00'XXXW       40°35.336'N40.676666774°00.005'W-74.00138889
  • It shouldn't and didn't in my example I showed.  The 'inner' Substitution will only replace the first instance  of "XXX" with the value from J2 and the 'outer' Substitution will then replace the remaining "XXX" with L2.  If you only want to replace the 2nd instance then try this:

    =SUBSTITUTE(B2,"XXX",LEFT(TEXTAFTER(L2,"."),3),2)

     

7 Replies

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    I suggest make a new column for the updated Name and you can use:

    =SUBSTITUTE(SUBSTITUTE(B2,"XXX",LEFT(TEXTAFTER(J2,"."),3),1),"XXX",LEFT(TEXTAFTER(L2,"."),3))

    I know you only asked for the Longitude one but just in case you needed both I did both figuring you could delete the part you don't need.  If you really don't want that Name2 column then you can do it, copy the column and then Paste Values Only overtop the Column B values.

     

    • Cygnata's avatar
      Cygnata
      Copper Contributor

      That replaces BOTH XXXs with the same value.

      • m_tarler's avatar
        m_tarler
        Bronze Contributor

        It shouldn't and didn't in my example I showed.  The 'inner' Substitution will only replace the first instance  of "XXX" with the value from J2 and the 'outer' Substitution will then replace the remaining "XXX" with L2.  If you only want to replace the 2nd instance then try this:

        =SUBSTITUTE(B2,"XXX",LEFT(TEXTAFTER(L2,"."),3),2)

         

  • IlirU's avatar
    IlirU
    Iron Contributor

    Hi,

     

    Try this formula:

     

    =SUBSTITUTE(TEXTAFTER(B2, "˜"), "'XXX", ".005'")

     

    or maybe you need this formula:

     

    =SUBSTITUTE(TEXTAFTER(B2, "˜"), "'XXXW", ".005'P")

     

    Hope this helps.

    IlirU

    • Cygnata's avatar
      Cygnata
      Copper Contributor

      The replacement text will never be the same, however.

      • IlirU's avatar
        IlirU
        Iron Contributor

         

        Ok then, you can use this formula:

         

        =REGEXREPLACE(TRIMRANGE(B2:B2500), "XXX", "005", 2)

         

        Change the range as per you need.

         

        Hope this helps.

        IlirU