Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA - Character Removal

I need to make a macro remove the 7th character in a string of text if the
first 6 letters match the specified criteria. But I don't know the best way
to handle...

This is what I want to do:
If the first 6 characters of a2="Albany", then delete the next character
(which in this case is ",").

If the above isn't true...then continue on with the remainder of the macro.

And continue to the next row.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VBA - Character Removal

for each cell in selection
if instr(1,cell.Value,"Albany",VbTextCompare) = 1 then
cell.Value = left(cell.Value,6) & Mid(cell.value,8)
end if
Next

This would remove rich text formatting.

if you want it to be a case sensitive match change vbTextCompare to
vbBinaryCompare

You can speed it up by using the find method of the range object and only
going to cells that contain Albany. Look at Excel VBA help at the FindNext
sample code.


--
Regards,
Tom Ogilvy


"Josh O." wrote:

I need to make a macro remove the 7th character in a string of text if the
first 6 letters match the specified criteria. But I don't know the best way
to handle...

This is what I want to do:
If the first 6 characters of a2="Albany", then delete the next character
(which in this case is ",").

If the above isn't true...then continue on with the remainder of the macro.

And continue to the next row.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default VBA - Character Removal

Thanks Tom. Work almost perfect. I just had to accomodate for the rare
occasion that "Albany" was followed by a space.

Appreciate the find next suggestion...I may implement that in near future.
For now this will work.

"Tom Ogilvy" wrote:

for each cell in selection
if instr(1,cell.Value,"Albany",VbTextCompare) = 1 then
cell.Value = left(cell.Value,6) & Mid(cell.value,8)
end if
Next

This would remove rich text formatting.

if you want it to be a case sensitive match change vbTextCompare to
vbBinaryCompare

You can speed it up by using the find method of the range object and only
going to cells that contain Albany. Look at Excel VBA help at the FindNext
sample code.


--
Regards,
Tom Ogilvy


"Josh O." wrote:

I need to make a macro remove the 7th character in a string of text if the
first 6 letters match the specified criteria. But I don't know the best way
to handle...

This is what I want to do:
If the first 6 characters of a2="Albany", then delete the next character
(which in this case is ",").

If the above isn't true...then continue on with the remainder of the macro.

And continue to the next row.

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
Excel 2007 - Formatting text in cell (character by character) TomC Excel Discussion (Misc queries) 0 January 29th 10 07:25 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
importing undelimited text file data, character-by-character The Mos$ Excel Programming 4 December 26th 05 11:01 AM
UnKnown Character Removal CyndyG Excel Worksheet Functions 2 April 28th 05 01:42 AM
Unknown Character removal Jerrard Excel Worksheet Functions 3 November 5th 04 10:46 PM


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