Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default vba to get file extension from col A file names

Hi: Excel2003. I have a list of file names in column A (340 rows). I want to
copy the extension (only) from each name in col A to col B -- so I can sort
the worksheet by file extension. There are about 15 extensions (.xls, .doc,
..lnk etc.) Can someone provide me the VBA code, or a starting point, to do
this?

TIA, Stephanie

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default vba to get file extension from col A file names

Give this macro a try...

Sub GetExtensions()
Dim X As Long
Dim LastRow As Long
Dim FName As String
With Worksheets("Sheet3")
LastRow = Worksheets("Sheet3").Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
FName = .Cells(X, "A").Value
.Cells(X, "B").Value = Mid(FName, InStrRev(FName, ".") + 1)
Next
End With
End Sub

--
Rick (MVP - Excel)


"StephCA" wrote in message
...
Hi: Excel2003. I have a list of file names in column A (340 rows). I want
to
copy the extension (only) from each name in col A to col B -- so I can
sort
the worksheet by file extension. There are about 15 extensions (.xls,
.doc,
.lnk etc.) Can someone provide me the VBA code, or a starting point, to do
this?

TIA, Stephanie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default vba to get file extension from col A file names

Rick, this was perfect. Thanks! One question: I'll always be running this on
the active worksheet. How can I specify the "active" sheet where you show
"sheet3" in the code. TIA again, Stephanie

"Rick Rothstein" wrote:

Give this macro a try...

Sub GetExtensions()
Dim X As Long
Dim LastRow As Long
Dim FName As String
With Worksheets("Sheet3")
LastRow = Worksheets("Sheet3").Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
FName = .Cells(X, "A").Value
.Cells(X, "B").Value = Mid(FName, InStrRev(FName, ".") + 1)
Next
End With
End Sub

--
Rick (MVP - Excel)


"StephCA" wrote in message
...
Hi: Excel2003. I have a list of file names in column A (340 rows). I want
to
copy the extension (only) from each name in col A to col B -- so I can
sort
the worksheet by file extension. There are about 15 extensions (.xls,
.doc,
.lnk etc.) Can someone provide me the VBA code, or a starting point, to do
this?

TIA, Stephanie



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default vba to get file extension from col A file names

Try this...

Sub GetExtensions()
Dim X As Long
Dim LastRow As Long
Dim FName As String
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
FName = .Cells(X, "A").Value
.Cells(X, "B").Value = Mid(FName, InStrRev(FName, ".") + 1)
Next
End With
End Sub

--
Rick (MVP - Excel)


"StephCA" wrote in message
...
Rick, this was perfect. Thanks! One question: I'll always be running this
on
the active worksheet. How can I specify the "active" sheet where you show
"sheet3" in the code. TIA again, Stephanie

"Rick Rothstein" wrote:

Give this macro a try...

Sub GetExtensions()
Dim X As Long
Dim LastRow As Long
Dim FName As String
With Worksheets("Sheet3")
LastRow = Worksheets("Sheet3").Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
FName = .Cells(X, "A").Value
.Cells(X, "B").Value = Mid(FName, InStrRev(FName, ".") + 1)
Next
End With
End Sub

--
Rick (MVP - Excel)


"StephCA" wrote in message
...
Hi: Excel2003. I have a list of file names in column A (340 rows). I
want
to
copy the extension (only) from each name in col A to col B -- so I can
sort
the worksheet by file extension. There are about 15 extensions (.xls,
.doc,
.lnk etc.) Can someone provide me the VBA code, or a starting point, to
do
this?

TIA, Stephanie




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default vba to get file extension from col A file names

For the archives... I left an extra reference to the worksheet inside the
With block (doesn't really hurt anything in the end, but it was
unnecessary). This is the code as it should have been posted...

Sub GetExtensions()
Dim X As Long
Dim LastRow As Long
Dim FName As String
With Worksheets("Sheet3")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
FName = .Cells(X, "A").Value
.Cells(X, "B").Value = Mid(FName, InStrRev(FName, ".") + 1)
Next
End With
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Give this macro a try...

Sub GetExtensions()
Dim X As Long
Dim LastRow As Long
Dim FName As String
With Worksheets("Sheet3")
LastRow = Worksheets("Sheet3").Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
FName = .Cells(X, "A").Value
.Cells(X, "B").Value = Mid(FName, InStrRev(FName, ".") + 1)
Next
End With
End Sub

--
Rick (MVP - Excel)


"StephCA" wrote in message
...
Hi: Excel2003. I have a list of file names in column A (340 rows). I want
to
copy the extension (only) from each name in col A to col B -- so I can
sort
the worksheet by file extension. There are about 15 extensions (.xls,
.doc,
.lnk etc.) Can someone provide me the VBA code, or a starting point, to
do
this?

TIA, Stephanie





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default vba to get file extension from col A file names

Do you want VBA?

You could do the same with DataText to ColumnsDelimited by a period.


Gord Dibben MS Excel MVP

On Fri, 3 Oct 2008 16:26:00 -0700, StephCA
wrote:

Hi: Excel2003. I have a list of file names in column A (340 rows). I want to
copy the extension (only) from each name in col A to col B -- so I can sort
the worksheet by file extension. There are about 15 extensions (.xls, .doc,
.lnk etc.) Can someone provide me the VBA code, or a starting point, to do
this?

TIA, Stephanie


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default vba to get file extension from col A file names

Yes. Needed VBA to add to an already written macro. And Rick's code is very
quick! Didn't know DataText, though. Thanks much for the tip. Stephanie

"Gord Dibben" wrote:

Do you want VBA?

You could do the same with DataText to ColumnsDelimited by a period.


Gord Dibben MS Excel MVP

On Fri, 3 Oct 2008 16:26:00 -0700, StephCA
wrote:

Hi: Excel2003. I have a list of file names in column A (340 rows). I want to
copy the extension (only) from each name in col A to col B -- so I can sort
the worksheet by file extension. There are about 15 extensions (.xls, .doc,
.lnk etc.) Can someone provide me the VBA code, or a starting point, to do
this?

TIA, Stephanie



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
Determine Excel file version with no file extension. tjlumpkin Excel Discussion (Misc queries) 2 July 23rd 09 06:59 AM
file format or file extension is not valid...error message Ballun Excel Discussion (Misc queries) 0 May 7th 09 09:06 PM
Additional file with no extension created during File Save As proc Peter Rooney Excel Discussion (Misc queries) 2 August 11th 05 02:48 PM
Saving two file names? One with no extension? Rick S.[_3_] Excel Programming 3 April 22nd 05 01:24 AM
I need to download an exel spreadsheet file. (file extension :xls) buckrogers Excel Discussion (Misc queries) 2 December 8th 04 11:08 PM


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