Macro to remove space at right end of character string
Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Macro to remove space at right end of character string

  1. #1
    Guest

    Default

     
    I am trying to write/record a macro that will eliminate a space at the end of each number. On a one-at-a-time basis, if you go to a cell, hit F2, left one space, shift-end delete and enter, the data in the cell is converted to a number. However, when I record a macro following those keystrokes, the macro enters the number contained in the cell on which the macro was recorded, not the number in the current active cell. I'm not sure what I should do to have the macro read the current cell's contents. (I clicked the relative reference button, but that's not solving the problem)

    Any help would be greatly appreciated.



  2. #2
    MrExcel MVP Aladin Akyurek's Avatar
    Join Date
    Feb 2002
    Location
    The Hague, NL
    Posts
    81,772
    Post Thanks / Like
    Mentioned
    11 Post(s)
    Tagged
    1 Thread(s)

    Default

    On 2002-02-27 07:07, Anonymous wrote:
    I am trying to write/record a macro that will eliminate a space at the end of each number. On a one-at-a-time basis, if you go to a cell, hit F2, left one space, shift-end delete and enter, the data in the cell is converted to a number. However, when I record a macro following those keystrokes, the macro enters the number contained in the cell on which the macro was recorded, not the number in the current active cell. I'm not sure what I should do to have the macro read the current cell's contents. (I clicked the relative reference button, but that's not solving the problem)

    Any help would be greatly appreciated.


    Why not use Data|Text to Columns?

  3. #3
    Guest

    Default

    Thanks to Aladin Ayurek for this solution:

    The last character in the cell is a number, which has the ascii code char(202) or in some other cases char(160). So the answer is :
    =if(isnumber(left(c4)+0), substitute(c4,char(160)" ")+0)

    (For some reason, the char(160) works on either code)


  4. #4
    Guest

    Default

    On 2002-02-27 07:07, Anonymous wrote:
    I am trying to write/record a macro that will eliminate a space at the end of each number. On a one-at-a-time basis, if you go to a cell, hit F2, left one space, shift-end delete and enter, the data in the cell is converted to a number. However, when I record a macro following those keystrokes, the macro enters the number contained in the cell on which the macro was recorded, not the number in the current active cell. I'm not sure what I should do to have the macro read the current cell's contents. (I clicked the relative reference button, but that's not solving the problem)

    Any help would be greatly appreciated.

    Use the "TRIM" function. It delets leading and trailing zeroc

  5. #5
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Hi

    Once you know the character set you can simply use some east code like this:

    Selection.Replace What:="" & Chr(10) & "", _
    Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False


    Or you can just type the character code in the Find box and leave the Replace empty.



User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com