Hi,
I'm new here ans have only basic understanding of VBA. However, once it works, I do love it. Here is my problem.
I'm trying to trim all the data in my worksheet in order to prepare it for several steps of further analysis. Running the below code will cause an error that I don't understand. It says:
Runtime error '1004': Application-defined or object-defined error
the code is (error causing line indicated in comments):
PHP Code:
Sub trimAll()
Application.ScreenUpdating = False
Dim Rows As Long
Dim Column As Long
Dim i As Integer
Rows = ActiveSheet.UsedRange.Rows.Count
Column = ActiveSheet.UsedRange.Columns.Count
For i = 1 To Column
Columns(i).Select
Selection.Insert Shift:=xlToRight
ActiveSheet.Range(Cells(1, i), Cells(Number, i)) = "=TRIM(RC[1])" ' ** ERROR **
Columns(i).Select
Selection.Copy
Columns(i + 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns(i).Select
Selection.Delete Shift:=xlToLeft
Next i
Application.ScreenUpdating = True
End Sub
Bookmarks