Saturday, July 3, 2010

Macro to clean and trim data


If you want to clean and trim selected cells in one go . Try this macro


Sub clean_and_trim_selected_range()

Dim cell_1 As Range

For Each cell_1 In Selection.Cells
    If cell_1.HasFormula = False And Not IsEmpty(cell_1) And Not IsDate(cell_1) Then
        cell_1.Value = Application.WorksheetFunction.Trim(Application.WorksheetFunction.Clean(cell_1.Value))
    End If
Next


End Sub


Steps to Use

  • Copy the below code
  • Press Alt+F11 to open VBA editor
  • Paste it in any public module or module 1
  • Select the cells & run the Macro

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...