Macro to remove space at right end of character string

G

Guest

Guest
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.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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?
 
Upvote 0
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)
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

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