Hi
Please bare with me, I am new to this forum and VBA. I have been working on a Macro that can be used to do
various tasks that we have found to be extremely tedious at work. The data I am working with is addresses, however
there is no standard column for the data, it may come in column G or F. I want the Macro to insert a column to the right
of this column, copy the information over and then alter the information in the new column only. Leaving the original
column with addresses untouched. Thats where I am stumped, I am not sure how to tell the macro to only alter the data
in the new column. I have made an attempt as can be seen in my code however I get run-time error 13 on line
Columns("clean").Select .
My macro so far is:
Sub CleanMe()
Application.ScreenUpdating = False
'Insert column to the right of the active cell
ActiveCell.EntireColumn.Offset(0, 1).Insert
' This module will populate the column to the right,with the same data found in the active cell
Selection.Copy
Cells(ActiveCell.Row, 2).Select
ActiveSheet.Paste
Dim insertedColumn As Integer
insertedColumn = ActiveCell.Column + 1
'The inserterColumnIndex value can then be used as follows:
Cells(ActiveCell.Row, insertedColumn).Value = "Clean"
' This module will remove the following characters: + # $ - / \.
Dim e As Object
Columns("clean").Select
With Selection
For Each e In [{"+","#","$","-","/","\"}]
Replace e, "", xlPart
Next
For Each e In [{"&"}]
Replace e, "AND", xlPart
Next
' This module will trim extra spaces from BOTH SIDES and excessive spaces from inside the text.
Dim MyCell As Range
On Error Resume Next
Selection.Cells.SpecialCells(xlCellTypeConstants, 23).Select
For Each MyCell In Selection.Cells
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
Next
End With
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Any help or tips would be greatly appreciated
Please bare with me, I am new to this forum and VBA. I have been working on a Macro that can be used to do
various tasks that we have found to be extremely tedious at work. The data I am working with is addresses, however
there is no standard column for the data, it may come in column G or F. I want the Macro to insert a column to the right
of this column, copy the information over and then alter the information in the new column only. Leaving the original
column with addresses untouched. Thats where I am stumped, I am not sure how to tell the macro to only alter the data
in the new column. I have made an attempt as can be seen in my code however I get run-time error 13 on line
Columns("clean").Select .
My macro so far is:
Sub CleanMe()
Application.ScreenUpdating = False
'Insert column to the right of the active cell
ActiveCell.EntireColumn.Offset(0, 1).Insert
' This module will populate the column to the right,with the same data found in the active cell
Selection.Copy
Cells(ActiveCell.Row, 2).Select
ActiveSheet.Paste
Dim insertedColumn As Integer
insertedColumn = ActiveCell.Column + 1
'The inserterColumnIndex value can then be used as follows:
Cells(ActiveCell.Row, insertedColumn).Value = "Clean"
' This module will remove the following characters: + # $ - / \.
Dim e As Object
Columns("clean").Select
With Selection
For Each e In [{"+","#","$","-","/","\"}]
Replace e, "", xlPart
Next
For Each e In [{"&"}]
Replace e, "AND", xlPart
Next
' This module will trim extra spaces from BOTH SIDES and excessive spaces from inside the text.
Dim MyCell As Range
On Error Resume Next
Selection.Cells.SpecialCells(xlCellTypeConstants, 23).Select
For Each MyCell In Selection.Cells
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
MyCell.Value = Application.WorksheetFunction.Substitute(Trim(MyCell.Value), " ", " ")
Next
End With
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Any help or tips would be greatly appreciated