Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Deleting unneeded characters in a cell

OK All,
I am just playing around learning this VBA stuff and decided to build a sub
routine that scans my hard drive for specific file types and puts them on
sheet1 of my spreadsheet and this works fine. I even have the second column
do a LEN so I know how many characters are in the path name, which leads to
the point I am at now and while I am continuing to work on it I think I need
some help. When the Sub Routine Runs, it lists my files as below:

C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\10cloth.tx t
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\10leather. txt
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\15cloth.tx t
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\15leather. txt
C:\Program Files\Adobe\Photoshop 7.0\Presets\Layouts\1stFiveBySevens.txt
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\20cloth.tx t

I am now wanting it to do a "right trim" I guess so that it populates column
3 with only the filename such as

10cloth.txt
10leather.txt
15cloth.txt
15leather.txt
1stFiveBySevens.txt
20cloth.txt

Then I can do a sort as on colum C and find duplicate files (Yes I know I
can just use FILE FIND, but I am doing this as a learning tool). I tried
doing the following to have it evaluate a characeter from right to left and
if it finds the "\" then it will delete everything to the left and including
the \ so that I am only left with the Filename. I am sure there are already
VBA functions out there that will do this but again, trying to learn and not
sure how to get it to evaluate just a character

C:\CBTLIB\CS1302E\CBTLIST.DBF 29


So in the above example the \ is at character 17 so I was thinking that when
it found the \ it would do a left delete to character 17 or something like
that.

Hope this was not too confusing.

TIA Wally Steadman




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Deleting unneeded characters in a cell

Dim pos As Long
Dim cell As Range

For Each cell In Selection
pos = InStrRev(cell.Value, "\")
If pos 0 Then
cell.Value = Right(cell.Value, Len(cell.Value) - pos)
End If
Next cell


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wally Steadman" wrote in message
...
OK All,
I am just playing around learning this VBA stuff and decided to build a

sub
routine that scans my hard drive for specific file types and puts them on
sheet1 of my spreadsheet and this works fine. I even have the second

column
do a LEN so I know how many characters are in the path name, which leads

to
the point I am at now and while I am continuing to work on it I think I

need
some help. When the Sub Routine Runs, it lists my files as below:

C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\10cloth.tx t
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\10leather. txt
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\15cloth.tx t
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\15leather. txt
C:\Program Files\Adobe\Photoshop 7.0\Presets\Layouts\1stFiveBySevens.txt
C:\Documents and Settings\wfsteadman\Desktop\thumb1\text\20cloth.tx t

I am now wanting it to do a "right trim" I guess so that it populates

column
3 with only the filename such as

10cloth.txt
10leather.txt
15cloth.txt
15leather.txt
1stFiveBySevens.txt
20cloth.txt

Then I can do a sort as on colum C and find duplicate files (Yes I know I
can just use FILE FIND, but I am doing this as a learning tool). I tried
doing the following to have it evaluate a characeter from right to left

and
if it finds the "\" then it will delete everything to the left and

including
the \ so that I am only left with the Filename. I am sure there are

already
VBA functions out there that will do this but again, trying to learn and

not
sure how to get it to evaluate just a character

C:\CBTLIB\CS1302E\CBTLIST.DBF 29


So in the above example the \ is at character 17 so I was thinking that

when
it found the \ it would do a left delete to character 17 or something like
that.

Hope this was not too confusing.

TIA Wally Steadman






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
Deleting unneeded rows and columns mbing916 Excel Discussion (Misc queries) 1 May 1st 07 07:08 PM
limiting or deleting extra characters in a cell dprichard Excel Discussion (Misc queries) 3 October 28th 05 09:57 PM
Deleting Blank Characters in a Cell PokerZan Excel Discussion (Misc queries) 4 June 3rd 05 09:43 PM
Deleting Unneeded Records Bill Foley[_2_] Excel Programming 16 July 9th 04 07:46 PM
deleting the last nine characters in a cell Chris Excel Programming 2 June 18th 04 04:03 PM


All times are GMT +1. The time now is 06:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"