Removing blank characters from left of field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to import data where there is sometimes a blank in the cell
before the data - space bar.

I need to get the VBA code to do something like "If left character is blank
then delete left character and move ramining chaacters to the left"

Tried a few different ways in VBA, but none seem to do the trick
 
Use LTrim function
[destination cell] = LTrim([Source cell])

Also search in VBA help on 'Trim' and see LTrim, Trim and RTrim
functions.

Sharad
 
Thank you, gave me a steer. The code didn't like the link to application, so
looked up trim in vba help.

Code I've now come up with looks like.

Sub trim_left()
Dim mystring, trimstring

Range("H3").Activate
mystring = ActiveCell
trimstring = LTrim(RTrim(mystring))

Range("i3") = trimstring



End Sub

with the value of ' 123456 in h3.

Many thanks
 
Instead of LTrim(RTrim(mystring)) you can use simply
Trim(mystring)

Sharad
 
Thanks both for the help on this one. Never heard of trim before. Very
useful. Happy New Year
 

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

Back
Top