Removing Space
Option Explicit
Sub testme()
dim myRng as range
dim myCell as range
with worksheets("sheet9999")
set myrng = .range("a1",.cells(.rows.count,"A").end(xlup))
end with
for each mycell in myrng.cells
mycell.value = ltrim(mycell.value)
'or
mycell.value = rtrim(mycell.value)
'or
mycell.value = trim(mycell.value)
'or
mycell.value = application.trim(mycell.value)
next mycell
end sub
Tom wrote:
On Feb 26, 11:31 am, Dave Peterson wrote:
Take a look at LTrim.
If you want to get right of the rightmost space characters, you'd use RTrim. If
you wanted to get rid of both leading and trailing spaces, you could use Trim.
And if you wanted to get rid of leading/trailing/duplicated internal spaces, you
could use application.trim.
Tom wrote:
Hello - When I import data, there is a space in front of the first
character in a cell. Would like to know if there is a visual basic
code to remove this space. I already have a code which removes all
spaces, now need code to remove the first space and leaves the other
spaces in place.
Thanks,
Tom
--
Dave Peterson
Could you please put in code format. I'm not very real versed in
writing visual basic code.
Thanks,
Tom
--
Dave Peterson
|