Auto-Trim through validation or the macro

S

SG

Dear Friends

I have a date with consisting of more than 1200 row and 15 columns;
When I use Pivot Table for this data; I use Trim () function by
linking in a additional worksheet and later on Special paste value
over original data to remove unnecessary spaces

My question is that is there any possibility to use auto Trim Function
through Validation or any other means. OR it is possible to create a
short through macro to use this trim function.

Looking for your help.
 
B

Bernie Deitrick

Data Validation:

Choose your cells (in this example, the active cell will be A1), the choose Data / Validation....
on the Settings tab, under Allow: choose Custom, then use the formula =A1=TRIM(A1)

You can set a message to say that they entry must not include extra spaces.

You can also use the change event: Copy this code, right-click the sheet tab, select "View Code" and
paste the code into the window that appears.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next
Application.EnableEvents = False
If Not Target.HasFormula Then _
Target.Value = Application.WorksheetFunction.Trim(Target.Value)
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top