ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trim the last two characters? (https://www.excelbanter.com/excel-programming/309151-trim-last-two-characters.html)

Craig[_8_]

Trim the last two characters?
 
Hi folks,
I'm new to VBA, but I've programmed in VB (a little bit)
before. I have several cells that I simply need to trim
off the last 2 characters from. Is there a function in
Excel that can do that?...or does someone know of a
function that will do that? I frequently have something
like: 373.62CR and I need to keep the numeric portion, but
lose the text portion. Suggestions???

Thanks,
Craig


Tom Ogilvy

Trim the last two characters?
 
Is the CR produced by formatting or is this actually part of the value of
the cell. If you select the cell is it shown in the formula bar?

Assuming it is part of the text in the cell

Sub Remove2()
for each cell in selection
if not cell.Hasformula then
cell.Value = Left(cell.value,len(Cell.Value)-2)
end if
Next
End Sub

Assume the value is in A1, in B1 =Left(A1,len(A1)-2)

then drag fill down the column.

--
Regards,
Tom Ogilvy

"Craig" wrote in message
...
Hi folks,
I'm new to VBA, but I've programmed in VB (a little bit)
before. I have several cells that I simply need to trim
off the last 2 characters from. Is there a function in
Excel that can do that?...or does someone know of a
function that will do that? I frequently have something
like: 373.62CR and I need to keep the numeric portion, but
lose the text portion. Suggestions???

Thanks,
Craig




duane[_11_]

Trim the last two characters?
 
have you tried left(ref,len(ref)-2)

--
Message posted from http://www.ExcelForum.com


Craig[_8_]

Trim the last two characters?
 
Hi Duane,
No, I haven't. Can you give me an example using the
Cells.Value concept (I don't quite understand the syntax
you've suggested), which is how I would be using it?

Thank you!
Craig


-----Original Message-----
have you tried left(ref,len(ref)-2)?


---
Message posted from http://www.ExcelForum.com/

.


Tom Ogilvy

Trim the last two characters?
 
I gave you an example with cells.value?
what what the problem with it?

--
Regards,
Tom Ogilvy

"Craig" wrote in message
...
Hi Duane,
No, I haven't. Can you give me an example using the
Cells.Value concept (I don't quite understand the syntax
you've suggested), which is how I would be using it?

Thank you!
Craig


-----Original Message-----
have you tried left(ref,len(ref)-2)?


---
Message posted from http://www.ExcelForum.com/

.





All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com