Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to delete first three characters in all rows of a field | Excel Discussion (Misc queries) | |||
Looking for alpha characters in a field | Excel Worksheet Functions | |||
How do I creat a macro to delete the first 20 cell characters | Excel Worksheet Functions | |||
Macro to delete row based on criteria (first few characters of string) | Excel Programming | |||
set up a macro to delete characters in each cell of a column | Excel Discussion (Misc queries) |