View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default Trim content of a column

Thanks Chip. Otto
"Chip Pearson" wrote in message
...
The $ character causes the function to return a String rather than a
Variant. It results in a (very slight) performance improvement.


"Otto Moehrbach" wrote in message
...
Myrna
If I may pick your brain for a minute, what is the function of the
dollar sign ($) after "Mid"? Thanks for your time. Otto
"Myrna Larson" wrote in message
...
Hi, Otto:

I think the InstrRev function would eliminate the inner loop, i.e.

Sub FindFileName()
Dim c As Long
Dim TheRng As Range
Dim i As Range

Set TheRng = Range("A1", Range("A" & Rows.Count).End(xlUp))
For Each i In TheRng
c = InstrRev(i.Value, "\")
If c < 0 then i.value = Mid$(i.Value, c + 1)
Next i
End Sub

On Wed, 31 Oct 2007 18:37:51 -0400, "Otto Moehrbach"

wrote:

This little macro will do that. I assumed your data started in A1 and
went
down. HTH Otto
Sub FindFileName()
Dim c As Long
Dim TheRng As Range
Dim i As Range
Set TheRng = Range("A1", Range("A" & Rows.Count).End(xlUp))
For Each i In TheRng
For c = 1 To 50
If Not InStr(Right(i.Value, c), "\") = 0 Then Exit For
Next c
i.Value = Right(i.Value, c - 1)
Next i
End Sub
"BZeyger" wrote in message
...
I have a worksheet that contains multiple columns. The first Column has
a
file path.
I would like to trim the path to only display the file name.


For example:
A
1 C:/test/folder/File1
2 C:/test/folder/File2
3 C:/test/folder/File3
4 C:/test/folder/File4
5 C:/test/folder/File5

Would like to display:

A
1 File1
2 File2
3 File3
4 File4
5 File5