Remove initial space from column of entries

justabc

Board Regular
Joined
Dec 6, 2002
Messages
86
After copying certain data into an excel worksheet, all entries in a column begin at 2nd space of each cell which I don't want. I can manually backspace each entry to the first space of each cell. But I cannot backspace all entries at once even if I try Find then put in a space for find and then in replace leave blank. Suggestions?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Highlight column.
Then from the Data drop down menu, select Text to Columns.
Select "Fixed Width" delimiter
Put a line after the first space, so you are parsing the data into two columns (the first just being a blank space)
Click Next
Select "Do Not Import" for the first column (blank space solumn)
Click Finish
 
Upvote 0
This code will remove the leading two charecters from column A

for r = 1 to Range("A65535").End(xlUp).row
temp = cells(r, 1)
l = 1
do until right(temp, l) = temp
l = l + 1
loop
cells(r,1) = right(cells(r, 1), l-2)
next r
 
Upvote 0
Your Find a space and Replace with null works fine for me on some test data I entered. Can you describe more clearly the type of data you have copied into your worksheet?
 
Upvote 0
Code:
Sub ReplaceLead()
a = ActiveSheet.UsedRange.Rows.Count
For i = 1 To a
celllength = Len(Cells(i, 1))
orgvalue = Cells(i, 1).Value
newvalue = Right(orgvalue, celllength - 1)
Cells(i, 1) = newvalue
Next i
End Sub

I'm sure this could be done much cleaner and quicker, but here's what I came up with.

Here it is again, only shorter

Code:
Sub ReplaceLead()
For i = 1 To ActiveSheet.UsedRange.Rows.Count
Cells(i, 2).Value = Right(Cells(i, 2), Len(Cells(i, 2)) - 1)
Next i
End Sub
 
Upvote 0
You could use the trim function on another sheet to refer to the cells on your sheet.
 
Upvote 0
another solution
you can cut the second character from your cell by use mid function. Let assume that your data in column A. Insert a blank column in B and type the following formula

=mid(A1,2,len(A1)-1)
=left(A1,len(A1)-1)
 
Upvote 0

Forum statistics

Threads
1,203,051
Messages
6,053,220
Members
444,648
Latest member
sinkuan85

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top