Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Chopping the last 4 characters of a string in VBA

Hi, is there is a way to chop off the last 4 characters of a string?

I have a group of text file names and I want to delete the ".txt" part
at the end of the names.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Chopping the last 4 characters of a string in VBA


"silkworm" wrote in message
ups.com...
Hi, is there is a way to chop off the last 4 characters of a string?

I have a group of text file names and I want to delete the ".txt" part
at the end of the names.

Thanks


If cell A1 contains a text value you want to parse, use this

=Left(A1, Len(A1) - 4)

HTH

-gk-


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Chopping the last 4 characters of a string in VBA

On 21 Dec 2005 18:05:37 -0800, "silkworm" wrote:

Hi, is there is a way to chop off the last 4 characters of a string?

I have a group of text file names and I want to delete the ".txt" part
at the end of the names.

Thanks



Since you're in the programming group, here is a VBA example:

Sub foo()
Const str As String = "foobar.txt"
Debug.Print Replace(str, ".txt", "")
End Sub

The above is case sensitive. If you want to do a case insensitive replacement,
then:

Option Compare Text
Sub foo()
Const str As String = "foobar.TXT"
Debug.Print Replace(str, ".txt", "")
End Sub


If you are doing this on a worksheet:

=SUBSTITUTE(A1,".txt","")

=REPLACE(A1,SEARCH(".txt",A1),4,"")

The SUBSTITUTE function is case sensitive. The other is not.


--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Chopping the last 4 characters of a string in VBA

Thank you very much, guys.

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
Counting Characters In A String fabio Excel Worksheet Functions 2 April 29th 10 11:01 AM
Extract characters from Right of string ashg657 Excel Worksheet Functions 5 July 30th 09 11:16 AM
Insert Leading Characters If String Is Only 7 Characters Paperback Writer Excel Discussion (Misc queries) 2 April 21st 09 09:07 PM
Copy string of characters BRB Excel Discussion (Misc queries) 4 August 27th 08 12:28 PM
how do I fit all data into a cell? Excel keeps chopping it into r jman Excel Discussion (Misc queries) 11 November 23rd 06 11:57 PM


All times are GMT +1. The time now is 10:21 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"