View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
dan dungan dan dungan is offline
external usenet poster
 
Posts: 411
Default Trim content of a column

Hi Otto and Myrna,

I must confess my ignorance because when I stepped through either of
these procedures, I could not see the file name--only the complete
path.

When I ran them, nothing changed in the spreadsheet.

I put
C:/test/folder/File1 in A1
C:/test/folder/File2 in A2
C:/test/folder/File3 in A3
C:/test/folder/File4 in A4
C:/test/folder/File5 in A5

Please show me what I'm missing.
Thanks,
Dan



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


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