Replace old content with new content base on Cell

trekker1218

Board Regular
Joined
Feb 15, 2018
Messages
86
Office Version
  1. 2019
Platform
  1. Windows
Sheet 1
ABCDEFGHI
1Old
A/C Condensing Units Residential
BTUVoltage SizeHeating
2New
A/C Condensing Units Residential​
Cooling BTUVoltageHeating BTU
3Old
A/C Unit Parts (OEM Only)
BTUHeatingAmperageVoltage Size
4New
A/C Unit Parts (OEM Only)
AC COOLING BTUHeating AreaAMPSAC VOLTAGE
5

Sheet 2
abcdefghi
1A/C Condensing Units ResidentialBTUVoltage SizeHeating
2A/C Unit Parts (OEM Only)BTUVoltage Size
Heating
3

I need a VBA or other solution for this:
I need to match the category in sheet1 B1 to Sheet2 A1 Then replace the old data in Sheet2 C1 with the new data in Sheet1 C2. It has to match the Category in Sheet 2 ColA because the old and new data does not always match the columns between sheets. But the OLD and NEW data will always be rows 1 & 2 and 3 & 4 etc...
I have a sheet2 with 50K lines of data that I need to find and replace old data with new data.

Result like this would be great.
abcdef
1A/C Condensing Units ResidentialCooling BTUVoltageHeating BTU
2A/C Unit Parts (OEM Only)AC COOLING BTUHeating AreaAMPSAC VOLTAGE
3
4

Even if it has to write an entire NEW sheet to move the data. That would work. I would just copy and paste the results to the file I need.

Thanks,
Tino
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
error pic attached
 

Attachments

  • Capture.JPG
    Capture.JPG
    16.5 KB · Views: 5
Upvote 0
Try:
VBA Code:
Sub matchData()
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, srcWS As Worksheet, x As Long, fnd As Range, i As Long, rng As Range
    Dim LastRow1 As Long, LastRow2 As Long, myArray1 As Variant, myString1 As String, DataRange1 As Range, lCol1 As Long, fVisRow1 As Long
    Set srcWS = ThisWorkbook.Sheets("Sheet1")
    Set desWS = ThisWorkbook.Sheets("Sheet2")
    LastRow1 = srcWS.Cells(srcWS.Rows.Count, "A").End(xlUp).Row
    LastRow2 = desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Row
    lCol1 = srcWS.Cells(1, srcWS.Columns.Count).End(xlToLeft).Column
    lCol2 = desWS.Rows(1).Find("Primary Attribute 30").Column
    For x = 2 To LastRow1 Step 2
        With srcWS.Cells(1).CurrentRegion
            .AutoFilter 2, srcWS.Cells(x, 2)
            fVisRow1 = srcWS.Range("A2", srcWS.Cells(srcWS.Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row
        End With
        With desWS.Cells(1).CurrentRegion
            .AutoFilter 1, srcWS.Cells(x, 2)
            fVisRow2 = desWS.Range("A2", desWS.Cells(desWS.Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row
        End With
        
        Set DataRange1 = srcWS.Range("D" & fVisRow1).Resize(, lCol1 - 3)
        For Each rng In DataRange1.Cells
            myString1 = myString1 & ";|;" & rng.Value & ";|;" & rng.Offset(1).Value
        Next rng
        myString1 = Right(myString1, Len(myString1) - 3)
        myArray1 = Split(myString1, ";|;")
        
        For i = LBound(myArray1) To UBound(myArray1) Step 2
            Set fnd = desWS.Rows(fVisRow2).Find(myArray1(i), LookIn:=xlValues, lookat:=xlWhole)
            If Not fnd Is Nothing Then
                With desWS
                    If myArray1(i + 1) <> "" Then
                        .Range(.Cells(2, fnd.Column), .Cells(LastRow2, fnd.Column)).SpecialCells(xlCellTypeVisible) = myArray1(i + 1)
                    End If
                End With
            End If
        Next i
        myString1 = ""
    Next x
    srcWS.Range("A1").AutoFilter
    desWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Holy Crap on a *******..... You did it...
AMAZING,.... it looks perfect on the test file.
I will try on larger files later and let you know.
How can I ever thank you.....
 
Upvote 0
Happy Thanksgiving to you and all your family....
As always, this board did not disappoint.
 
Upvote 0
Thank you and to you as well. Hopefully, we finally got there.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

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