Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22
Default Remove Last x Character(s) in Selected Cells

How do you remove the last two digits in a cell using a macro?

--
Thanks a bunch!
rojobrown
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,311
Default Remove Last x Character(s) in Selected Cells

One way using the active cell:
ActiveCell.Value = Left(ActiveCell.Value, Len(ActiveCell.Value) - 2)

If you want a specific cell reference:
Range("A1").Value = Left(Range("A1").Value, Len(Range("A1").Value) - 2)

HTH,
Paul

"rojobrown" wrote in message
...
How do you remove the last two digits in a cell using a macro?

--
Thanks a bunch!
rojobrown



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,624
Default Remove Last x Character(s) in Selected Cells

One way:

Public Sub RemoveLastXCharacters()
Const cnX As Long = 2
Dim rCell As Range
Dim nLen As Long
For Each rCell In Selection
With rCell
nLen = Len(.Text) - cnX
If nLen <= 0 Then
.ClearContents
Else
.Value = Left(.Text, nLen)
End If
End With
Next rCell
End Sub

Note: If the values are numeric, the last two digits will be "removed",
but the number of displayed digits will still be set by the number
format, so

1.2345

will display as

1.2300

if the format displays 4 digits after then decimal place.

In article ,
rojobrown wrote:

How do you remove the last two digits in a cell using a macro?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,355
Default Remove Last x Character(s) in Selected Cells

Here's an equation to do it in helper column

=left(A1,len(A1)-2)

Do you need it in a macro?

"rojobrown" wrote:

How do you remove the last two digits in a cell using a macro?

--
Thanks a bunch!
rojobrown

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22
Default Remove Last x Character(s) in Selected Cells

I do. Would you be able to help me?
--
Thanks a bunch!
rojobrown


"Barb Reinhardt" wrote:

Here's an equation to do it in helper column

=left(A1,len(A1)-2)

Do you need it in a macro?

"rojobrown" wrote:

How do you remove the last two digits in a cell using a macro?

--
Thanks a bunch!
rojobrown



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 24
Default Remove Last x Character(s) in Selected Cells

This formula works great! But, can you explain/translate the formula?

"Barb Reinhardt" wrote:

Here's an equation to do it in helper column

=left(A1,len(A1)-2)

Do you need it in a macro?

"rojobrown" wrote:

How do you remove the last two digits in a cell using a macro?

--
Thanks a bunch!
rojobrown

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default Remove Last x Character(s) in Selected Cells

LEFT and LEN are both standard Excel functions. Their operation and syntax,
and the operation and syntax of every Excel function except DATEDIF, is
shown in Excel help. One of many ways of getting to Excel help is to hit
the F1 button. I would heartily recommend it as a first port of call.
--
David Biddulph


"KrispyData" wrote in message
...
This formula works great! But, can you explain/translate the formula?

"Barb Reinhardt" wrote:

Here's an equation to do it in helper column

=left(A1,len(A1)-2)

Do you need it in a macro?

"rojobrown" wrote:

How do you remove the last two digits in a cell using a macro?

--
Thanks a bunch!
rojobrown



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
remove special character at end of string captain bob Excel Discussion (Misc queries) 0 August 3rd 06 02:59 PM
How to remove a character from the first index? dex Excel Discussion (Misc queries) 3 January 6th 06 05:33 AM
Remove a particular character using formulas msetyon Excel Discussion (Misc queries) 2 December 1st 05 08:46 PM
Remove last character of text string Grant Excel Worksheet Functions 2 September 29th 05 05:17 PM
Remove all characters following the first character in a string RC Excel Discussion (Misc queries) 5 August 30th 05 03:17 AM


All times are GMT +1. The time now is 05:46 PM.

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

About Us

"It's about Microsoft Excel"