Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for Removing Characters
Hello,
I was wondering if there's a way to make a macro or sub that will remove the last four characters of the value that is in the cells I select? I tried to record a macro but when I looked at it in the editor all it did was have the below... Range("G4").Select ActiveCell.FormulaR1C1 = "Test Remove Value " The value used to read "Test Remove Value Text" The issue is that the value is a series of random whatever and I want to be able to select a bunch of cells all at once and then have it remove just the last four characters. Thanks Very Much In Advance. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for Removing Characters
This should do what you want...
Sub RemoveLast4Characters() Dim C As Range For Each C In Selection C.Value = Left(C.Value, Len(C.Value) - 4) Next End Sub Rick "Rob" wrote in message ... Hello, I was wondering if there's a way to make a macro or sub that will remove the last four characters of the value that is in the cells I select? I tried to record a macro but when I looked at it in the editor all it did was have the below... Range("G4").Select ActiveCell.FormulaR1C1 = "Test Remove Value " The value used to read "Test Remove Value Text" The issue is that the value is a series of random whatever and I want to be able to select a bunch of cells all at once and then have it remove just the last four characters. Thanks Very Much In Advance. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for Removing Characters
for each c in selection
c.value=left(c,len(c)-4) next c -- Don Guillett Microsoft MVP Excel SalesAid Software "Rob" wrote in message ... Hello, I was wondering if there's a way to make a macro or sub that will remove the last four characters of the value that is in the cells I select? I tried to record a macro but when I looked at it in the editor all it did was have the below... Range("G4").Select ActiveCell.FormulaR1C1 = "Test Remove Value " The value used to read "Test Remove Value Text" The issue is that the value is a series of random whatever and I want to be able to select a bunch of cells all at once and then have it remove just the last four characters. Thanks Very Much In Advance. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for Removing Characters
OMGoodness! That worked perfectly! Thank you so much.
Mind if I ask how long it took to learn how to do this kind of stuff? It's so hard for me to get a grasp on it, so much so that everytime I try I just cannot seem to pick it up. Thanks Again! "Rick Rothstein (MVP - VB)" wrote: This should do what you want... Sub RemoveLast4Characters() Dim C As Range For Each C In Selection C.Value = Left(C.Value, Len(C.Value) - 4) Next End Sub Rick "Rob" wrote in message ... Hello, I was wondering if there's a way to make a macro or sub that will remove the last four characters of the value that is in the cells I select? I tried to record a macro but when I looked at it in the editor all it did was have the below... Range("G4").Select ActiveCell.FormulaR1C1 = "Test Remove Value " The value used to read "Test Remove Value Text" The issue is that the value is a series of random whatever and I want to be able to select a bunch of cells all at once and then have it remove just the last four characters. Thanks Very Much In Advance. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for Removing Characters
That is a hard question to answer. I have been programming in various
languages since 1981 and I still manage to learn new things from others by reading the various postings on these newsgroups. I don't mean that to be discouraging by any means; I just want to point out that you can never know it all. However, you should try to learn the basics, and the syntax for it, of whatever language you are learning (VBA in your case I would guess). That means, variable declaration (that being the various data types available), variable assignments, loops (For-Next, Do-Loop) and branching (If-Then, Select Case)... these are common to all languages, but can be implemented differently in each. Next, you should familiarize yourself with the various functions and statements the language offers (usually there is a Reference section in the help files to aid you in this). Note I said familiarize, not memorize; eventually you will memorize the key components you use over and over again, but it is important to "know" that you have seen a function or statement that does something similar to what you are thinking you want to do... you can always look up the syntax later, but if you know it exists, it will become part of your "code thinking" process as you develop your programs; and, conversely, if you do not "know" there is a function or statement that does something similar to what you want, you will miss that avenue of approach (obviously, since it can't occur to you to consider it) when developing your solution. After that, familiarize yourself with "scope"... this has to do with where your variables, subroutines and functions can be seen (where you declare them determines how much exposure they have). That will get you started, but the most important way to learn a language is to practice, practice, practice. And don't be afraid of mistakes... the more you make, the more you learn. I'm serious when I say that. Develop some code that you think should work, and when it fails to work correctly, the process of debugging (correcting the mistakes) will show you where your original thinking was wrong and this process tends to be remembered afterwards... you will not tend to make the same mistakes over and over and over again (maybe once, twice or even three times, but after awhile, you will learn how to correctly handle the situation). Rick "Rob" wrote in message ... OMGoodness! That worked perfectly! Thank you so much. Mind if I ask how long it took to learn how to do this kind of stuff? It's so hard for me to get a grasp on it, so much so that everytime I try I just cannot seem to pick it up. Thanks Again! "Rick Rothstein (MVP - VB)" wrote: This should do what you want... Sub RemoveLast4Characters() Dim C As Range For Each C In Selection C.Value = Left(C.Value, Len(C.Value) - 4) Next End Sub Rick "Rob" wrote in message ... Hello, I was wondering if there's a way to make a macro or sub that will remove the last four characters of the value that is in the cells I select? I tried to record a macro but when I looked at it in the editor all it did was have the below... Range("G4").Select ActiveCell.FormulaR1C1 = "Test Remove Value " The value used to read "Test Remove Value Text" The issue is that the value is a series of random whatever and I want to be able to select a bunch of cells all at once and then have it remove just the last four characters. Thanks Very Much In Advance. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for Removing Characters
Your comments are one of the best short-advice-clips I have read! Thanks
(Copy/Paste/Save) EagleOne "Rick Rothstein \(MVP - VB\)" wrote: That is a hard question to answer. I have been programming in various languages since 1981 and I still manage to learn new things from others by reading the various postings on these newsgroups. I don't mean that to be discouraging by any means; I just want to point out that you can never know it all. However, you should try to learn the basics, and the syntax for it, of whatever language you are learning (VBA in your case I would guess). That means, variable declaration (that being the various data types available), variable assignments, loops (For-Next, Do-Loop) and branching (If-Then, Select Case)... these are common to all languages, but can be implemented differently in each. Next, you should familiarize yourself with the various functions and statements the language offers (usually there is a Reference section in the help files to aid you in this). Note I said familiarize, not memorize; eventually you will memorize the key components you use over and over again, but it is important to "know" that you have seen a function or statement that does something similar to what you are thinking you want to do... you can always look up the syntax later, but if you know it exists, it will become part of your "code thinking" process as you develop your programs; and, conversely, if you do not "know" there is a function or statement that does something similar to what you want, you will miss that avenue of approach (obviously, since it can't occur to you to consider it) when developing your solution. After that, familiarize yourself with "scope"... this has to do with where your variables, subroutines and functions can be seen (where you declare them determines how much exposure they have). That will get you started, but the most important way to learn a language is to practice, practice, practice. And don't be afraid of mistakes... the more you make, the more you learn. I'm serious when I say that. Develop some code that you think should work, and when it fails to work correctly, the process of debugging (correcting the mistakes) will show you where your original thinking was wrong and this process tends to be remembered afterwards... you will not tend to make the same mistakes over and over and over again (maybe once, twice or even three times, but after awhile, you will learn how to correctly handle the situation). Rick "Rob" wrote in message ... OMGoodness! That worked perfectly! Thank you so much. Mind if I ask how long it took to learn how to do this kind of stuff? It's so hard for me to get a grasp on it, so much so that everytime I try I just cannot seem to pick it up. Thanks Again! "Rick Rothstein (MVP - VB)" wrote: This should do what you want... Sub RemoveLast4Characters() Dim C As Range For Each C In Selection C.Value = Left(C.Value, Len(C.Value) - 4) Next End Sub Rick "Rob" wrote in message ... Hello, I was wondering if there's a way to make a macro or sub that will remove the last four characters of the value that is in the cells I select? I tried to record a macro but when I looked at it in the editor all it did was have the below... Range("G4").Select ActiveCell.FormulaR1C1 = "Test Remove Value " The value used to read "Test Remove Value Text" The issue is that the value is a series of random whatever and I want to be able to select a bunch of cells all at once and then have it remove just the last four characters. Thanks Very Much In Advance. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Removing 2-3 characters at the end | Excel Worksheet Functions | |||
removing characters | Excel Discussion (Misc queries) | |||
Removing characters | Excel Discussion (Misc queries) | |||
Removing characters | Excel Worksheet Functions | |||
Removing characters | Excel Programming |