Sorry there was an error in the code. Here:
Option Explicit
Sub CompareAndChange()
Dim RowCheck As Long
Dim LastRow As Long
Dim LastColumn As Integer
Dim Ws As Worksheet
Dim Wb As Workbook
Dim DataRng As Range
Application.ScreenUpdating = False
Set Ws = ActiveSheet
Set Wb = ActiveWorkbook
With Ws
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastColumn = .Cells.SpecialCells(xlCellTypeLastCell).Column
Set DataRng = .Range(.Cells(1, 1), .Cells(1, LastColumn))
End With
DataRng.AutoFilter
With ActiveWorkbook.Worksheets(Ws.Name).AutoFilter.Sort
.SortFields.Clear
.SortFields.Add Key:=Ws.Cells(1, 1), SortOn:=xlSortOnValues _
, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
DataRng.AutoFilter
With Ws
For RowCheck = 2 To LastRow
If .Cells(RowCheck, 1).Value = .Cells(RowCheck - 1, 1).Value Then
.Cells(RowCheck - 1, 10).Value = .Cells(RowCheck, 10).Value
End If
Next RowCheck
End With
Application.ScreenUpdating = True
End Sub
Try this and tell me
Bookmarks