#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Removing Space

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

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 66
Default Removing Space

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


ltrim?

beege
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Removing Space

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
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Removing Space

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

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 23
Default Removing Space

Spaces don't normally occur in Excel cells except in text entries. If your
problem is that they are really spaces, you can remove them with the Replace
function. Search for (type in a space) and Replace with (nothing--leave box
empty). Be sure not to delete spaces in the text entries. If they aren't
really spaces entered with the spacebar, you may have to look for a
different number format (Format-Cells).

"Tom" wrote in message
ups.com...
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



  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Removing Space

On Feb 26, 1:58 pm, "Richard O. Neville"
wrote:
Spaces don't normally occur in Excel cells except in text entries. If your
problem is that they are really spaces, you can remove them with the Replace
function. Search for (type in a space) and Replace with (nothing--leave box
empty). Be sure not to delete spaces in the text entries. If they aren't
really spaces entered with the spacebar, you may have to look for a
different number format (Format-Cells).

"Tom" wrote in message

ups.com...



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- Hide quoted text -


- Show quoted text -


I got Dave's code to run (though chugs a little???). When I tried
using the "Find Replace" it removed all spaces. Just wanted the first
spaces removed.

Thanks to both of you for helping me. Much appreciated.
Tom

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Removing Space

If your data is in a single column, and you could get rid of leading and
trailing spaces, you could use:

Select the column
Data|Text to columns
Fixed width
(Remove any lines that excel guessed)
and finish up

If you have lots of columns, you can do the same thing for each column.

Record a macro when you test it manually to see the code.

(This'll be a lot quicker.)

Tom wrote:

On Feb 26, 1:58 pm, "Richard O. Neville"
wrote:
Spaces don't normally occur in Excel cells except in text entries. If your
problem is that they are really spaces, you can remove them with the Replace
function. Search for (type in a space) and Replace with (nothing--leave box
empty). Be sure not to delete spaces in the text entries. If they aren't
really spaces entered with the spacebar, you may have to look for a
different number format (Format-Cells).

"Tom" wrote in message

ups.com...



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- Hide quoted text -


- Show quoted text -


I got Dave's code to run (though chugs a little???). When I tried
using the "Find Replace" it removed all spaces. Just wanted the first
spaces removed.

Thanks to both of you for helping me. Much appreciated.
Tom


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Space KL Cheong Excel Discussion (Misc queries) 7 April 28th 06 07:32 AM
NEED HELP-----Removing a space at the end of a string of character FRS Excel Discussion (Misc queries) 7 April 13th 06 03:57 AM
removing a space between words in a cell JenBasch Excel Worksheet Functions 3 September 20th 05 12:39 AM
Removing a space after a comma DebbieK9 New Users to Excel 3 April 1st 05 10:08 PM
Removing a space within a cell JERRY8 Excel Worksheet Functions 3 December 2nd 04 03:22 AM


All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"