Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Macro to delete characters in field

I want to create a simple macro that will start at the active cell and delete
the first 4 characters and then move the next cell and delete the first 4
characters and so on. Can this be done. I tried to record it using the
keyboard and it takes the cell contents and copies it to the next cell.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Macro to delete characters in field

A fixed range or a variable one - if fixed

on error resume next
'error trap in case you haven't got 4 characters or more
for each cell in range("A1:A100") ' or whatever the range is
'cell is simply a variable in this context
cell.value=right(cell.value,len(cell.value)-4)
next

  #3   Report Post  
Posted to microsoft.public.excel.programming
DS DS is offline
external usenet poster
 
Posts: 117
Default Macro to delete characters in field

Hi Lisa,

try:

Sub ShortenIt()

Range("A1").Select
Do
Do Until Selection = ""
Selection = Right$(Selection, (Len(Selection) - 4))
Selection.Offset(1, 0).Select
Exit Do
Loop
Loop Until Selection = ""

End Sub

Your method of moving through the range you want can vary, but the central
part will work for varying length entries. (note that this is set to run
through column A from A1 until it hits a blank cell, change this if you need
a different range to be checked!)

HTH
DS



"LisaVH" wrote:

I want to create a simple macro that will start at the active cell and delete
the first 4 characters and then move the next cell and delete the first 4
characters and so on. Can this be done. I tried to record it using the
keyboard and it takes the cell contents and copies it to the next cell.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Macro to delete characters in field

Thanks to you both. That was exactly what I needed.

"DS" wrote:

Hi Lisa,

try:

Sub ShortenIt()

Range("A1").Select
Do
Do Until Selection = ""
Selection = Right$(Selection, (Len(Selection) - 4))
Selection.Offset(1, 0).Select
Exit Do
Loop
Loop Until Selection = ""

End Sub

Your method of moving through the range you want can vary, but the central
part will work for varying length entries. (note that this is set to run
through column A from A1 until it hits a blank cell, change this if you need
a different range to be checked!)

HTH
DS



"LisaVH" wrote:

I want to create a simple macro that will start at the active cell and delete
the first 4 characters and then move the next cell and delete the first 4
characters and so on. Can this be done. I tried to record it using the
keyboard and it takes the cell contents and copies it to the next cell.

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
How to delete first three characters in all rows of a field No Name Excel Discussion (Misc queries) 2 March 9th 09 04:43 PM
Looking for alpha characters in a field fgwiii[_2_] Excel Worksheet Functions 1 September 17th 08 12:41 PM
How do I creat a macro to delete the first 20 cell characters Bobo-ack Excel Worksheet Functions 5 April 20th 07 03:00 AM
Macro to delete row based on criteria (first few characters of string) [email protected] Excel Programming 5 May 15th 06 06:11 PM
set up a macro to delete characters in each cell of a column Rick Excel Discussion (Misc queries) 2 September 18th 05 03:02 AM


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