In Excel,
I have a bunch of information on Sheet1/column A and would like to search specific text (starting from the word N1*PE* up to the 9 numbers before "~N"),
And then compare (Sheet1/Column A) from the correct list (Sheet2/Column A) & then paste it on a separate worksheet (Sheet3/Column A).
Here's an example:
In Sheet 1 Column A : (I have WRONG information below)
EDI DEPARTMENT*TE*2658018518~N1*PE* ELMHUR
ST CENTER*XX*564824568~N4*GREAT NECK*NY*11023
N1*PECOOPERXX*333333333~N4*NEW YORK*NY*10077-5281~REF*TJ*133988001~LX*7111~
As you noticed, the word ELMHURST is broken.
What I would like to accomplish is to replace the wrong text (on Sheet1/Column A) based from the sample list (On Sheet2/Column A) and paste it on Sheet3/Column A --> using the same format.
Here's the (CORRECT) Sample Information List (Sheet2/Column A):
N1*PEELMHURST CENTERXX*454545457
N1*PECOOPERXX*123457777
So, in the result should be:
In Sheet3/Column A...
EDI DEPARTMENT*TE*2658018518~N1*PE* ELMHUR
ST CENTER*XX*454545457~N4*GREAT NECK*NY*11023
N1*PECOOPERXX*123457777~N4*NEW YORK*NY*10077-5281~REF*TJ*133988001~LX*7111~
The Code below is incomplete. As it can only copy and paste on Sheet2 Column A.
Option Explicit
Public Sub Transfer()
Dim lngRow As Long, lngWriteRow As Long, strTemp As String
Dim shtRaw As Worksheet, shtNew As Worksheet
' Initialize
lngWriteRow = 1 'The row we're writing to
Set shtRaw = Sheets("Sheet1") 'The raw data worksheet
Set shtNew = Sheets("Sheet2") 'The sheet with the concatenated text
For lngRow = 1 To shtRaw.UsedRange.Rows.Count
If InStr(1, shtRaw.Cells(lngRow, 1), "N1*PE*", vbTextCompare) > 0 Then
' Grab the end of this cell's text starting at N1*PE*
strTemp = Mid(shtRaw.Cells(lngRow, 1), InStr(1, shtRaw.Cells
(lngRow, 1), "N1*PE*", vbTextCompare))
' Add the start of the next cell's text, up to the ~N
strTemp = strTemp & Left(shtRaw.Cells(lngRow + 1, 1), InStr(1, shtRaw.Cells(lngRow + 1, 1), "~N", vbTextCompare))
' Write the concatenated string to the other worksheet
shtNew.Cells(lngWriteRow, 1) = strTemp
' NEED TO DO SOMETHING HERE... COMPARE THE TEXT FROM THE LIST AND PASTE IT ON SHEET 3 COLUMN A
' Move down one row for the next time we write to the other sheet
lngWriteRow = lngWriteRow + 1
End If
Next lngRow
'Sort the NPIs
Sheets("Sheet2").Select
Range("A:A").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes
' Clean up memory
Set shtRaw = Nothing
Set shtNew = Nothing
End Sub
Many Thanks in advance...