i hope u'r fine.
I have an ID Column containing some Blank Cells with spaces inside and other cells with information some of which with space & others with #
the aims is to apply TRIM function into the ID column and delete Blank Cells and Special Characters. Rm : if I try to make deleting of the Blank cells before Applying Trim function VBA will not recognize them as empty cells. but even after Applying Trim function Still not recognize them as empty cells. Same Story with # So I tried to make TRIM function and then copy Paste Column with only a value to delete TRIM Function in case. but same probleme. Tanks for your help
Here is the code
Sub Trim()
Dim Worksht As Worksheet
Dim TargetCell As Range
Dim DurtyRows As Range
Set Worksht = ActiveSheet
Set TargetCell = ActiveSheet.UsedRAnge.Find(What:="ID", LookAt:=xlWhole)
Range(TargetCell.Offset(1, 0), TargetCell.Offset(1, 0).End(xlDown)).Copy
TargetCell.Offset(1, 1).Select
'To Apply TRIM Function in an copied column
ActiveSheet.Paste
Application.CutCopyMode = False
TargetCell.Offset(1, 1).Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
Selection.AutoFill Destination:=Range(TargetCell.Offset(1, 1),
TargetCell.Offset(1, 1).End(xlDown))
'Replacing the initial Column with TRIM Function Result Column
Range(TargetCell.Offset(1, 1), TargetCell.Offset(1, 1).End(xlDown)).Copy
TargetCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range(TargetCell.Offset(1, 1), TargetCell.Offset(1, 1).End(xlDown)).Delete
Range(TargetCell.Offset(1, 0), TargetCell.Offset(1, 0).End(xlDown)).Select
''''the error message for.SpecialCells (xlCellTypeBlanks) " no corresponding
''cell
Set DurtyRows = ActiveSheet.Range(TargetCell.Offset(1, 0), TargetCell.Offset(1, 0).End(xlDown)).SpecialCells(xlCellTypeBlanks)
DurtyRows.Delete
End Sub