The code below should copy values from a cell and paste its first 10 characters to the same cell in the range. On this line:
Sh.Cells(i, 5) = Left(Sh.Cells(i, 5).Value, 10).Copy
I get a run-time error '424' (object required). Adding "set" before the line does not work. Does anyone know why is the error triggered here?
Sub fixCellsValue()
Dim wrk As Workbook
Dim Sh As Worksheet
Dim SourceFolder As String
Dim i As Long, lastrow As Long
SourceFolder = ThisWorkbook.PATH & "\source"
If Dir(SourceFolder & "Filename.*") <> "" Then
Set wrk = Application.Workbooks.Open(SourceFolder & "\Filename.xlsx")
Set Sh = wrk.Worksheets(1)
lastrow = Sh.Cells(Sh.Rows.Count, "A").End(xlUp).row
For i = 2 To lastrow
If Len(Sh.Cells(i, 5)) > 10 Then
Sh.Cells(i, 5) = Left(Sh.Cells(i, 5).Value, 10).Copy
Sh.Cells(i, 5).PasteSpecial Paste:=xlPasteValues
Sh.Cells(i,5).Interior.ColorIndex = 6
End If
Next i
End If
End sub