Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DK DK is offline
external usenet poster
 
Posts: 21
Default How to extract file extensions?

I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to extract file extensions?

You could use a formula in column G:
=if(mid(f1,len(f1)-3,1)=".",right(f1,3),"")
to show xxx.

=if(mid(f1,len(f1)-3,1)=".",right(f1,4),"")
to show .xxx

In code:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("F1", .Cells(.Rows.Count, "F").End(xlUp))
End With

For Each myCell In myRng.Cells
If Mid(myCell.Value, Len(myCell.Value) - 3, 1) = "." Then
myCell.Offset(0, 1).Value = Right(myCell.Value, 3)
'should column F have the extension dropped?
'myCell.Value = Left(myCell.Value, Len(myCell.Value) - 4)
Else
myCell.Offset(0, 1).Value = ""
End If
Next myCell
End Sub







DK wrote:

I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
DK DK is offline
external usenet poster
 
Posts: 21
Default How to extract file extensions?

Thank you so much Dave!
I will test this out!

Dave Peterson wrote:
You could use a formula in column G:
=if(mid(f1,len(f1)-3,1)=".",right(f1,3),"")
to show xxx.

=if(mid(f1,len(f1)-3,1)=".",right(f1,4),"")
to show .xxx

In code:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("F1", .Cells(.Rows.Count, "F").End(xlUp))
End With

For Each myCell In myRng.Cells
If Mid(myCell.Value, Len(myCell.Value) - 3, 1) = "." Then
myCell.Offset(0, 1).Value = Right(myCell.Value, 3)
'should column F have the extension dropped?
'myCell.Value = Left(myCell.Value, Len(myCell.Value) - 4)
Else
myCell.Offset(0, 1).Value = ""
End If
Next myCell
End Sub







DK wrote:

I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?


--

Dave Peterson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to extract file extensions?


"DK" wrote in message
ps.com...
I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?


Put this together for use in an Access database I worked on a while back -
not claiming its the best way - some of the more knowledgeable people around
here may be able to point out a better method - but its always worked for
me.
Good luck - Sean

Private Function GetExtension(ByVal strPath As String) As String
'Get file extension from file name
Dim intPtLoc As Integer
intPtLoc = InStrRev(strPath, ".")
GetExtension = UCase(Right(strPath, (Len(strPath) - (intPtLoc))))
End Function


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to extract file extensions?


"What-A-Tool" wrote in message
...

"DK" wrote in message
ps.com...
I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?


Put this together for use in an Access database I worked on a while back -
not claiming its the best way - some of the more knowledgeable people
around here may be able to point out a better method - but its always
worked for me.
Good luck - Sean

Private Function GetExtension(ByVal strPath As String) As String
'Get file extension from file name
Dim intPtLoc As Integer
intPtLoc = InStrRev(strPath, ".")
GetExtension = UCase(Right(strPath, (Len(strPath) - (intPtLoc))))
End Function


Sorry - saw Dave Petersons post after I sent mine, and realized I answered a
different question than u asked.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default How to extract file extensions?

=IF(MID(RIGHT(E1,4),1,1)=".",RIGHT(E1,3),"none")

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"DK" wrote:
I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?

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
don't want see file name with extensions. Rao Ratan Singh Excel Discussion (Misc queries) 7 March 14th 09 04:39 PM
File extensions colleen Excel Discussion (Misc queries) 3 September 16th 08 11:18 PM
File extensions Mex Excel Discussion (Misc queries) 5 August 4th 08 08:05 PM
File Extensions Robin Clay[_4_] Excel Programming 2 February 26th 06 03:49 AM
XML file extensions Rowan Excel Discussion (Misc queries) 2 April 22nd 05 07:54 AM


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

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"