Welcome this video will present a macro
approach to an earlier video on removing
characters from the left of
each cell in a selection.
As we can see, we have a list of expenses like
in the earlier video which used Excel
functions to remove characters.
To create a macro alternative
go to Visual Basic for Applications.
Click on "Insert" to add a "Module".
From a best practice perspective, always add
"Option Explicit" at the top of the module
because it will force us to declare object
variables for a specific macro.
Remember to notate your
macro for future reference.
First, we want to disable these Excel properties.
This will enhance the
speed and efficiency of our macro.
Now we want to declare the specific
object variables for our macro.
"selectedCells" will be the range of cells
processed in the macro.
"inputVar" will be the number of characters,
which we stipulate that we want to remove
from the left of each selected cell.
Therefore we must add an
input box syntax into our macro.
Next, we need looping code to cycle
through all the cells in the selected range.
It's always recommended to add an
error handler into a macro.
As it will minimise the chance of
run-time errors with your macro.
This line of code must be written accurately,
otherwise the macro won't successfully
remove the characters as required.
Hence take your time to write
this area of code.
As notated, the code will exit the macro if
the selected cell range contains nothing.
Otherwise the macro can move to
the next cell in the selected range.
The macro has looped through all the
selected cells, therefore we can return the
cursor to the first cell in the selected range.
The macro is complete, we can now re-enable
our Excel properties that were earlier disabled.
Let's review our macro one final time.
rngRangeXLeftCharacters.
We will run the macro on the
Description values in column G.
And then on the Canadian dollar amounts in
column I to remove the "CAD".
As we can see, the macro is
correctly removing characters from the left.
Feel free to like this video, comment
on this post or subscribe to our channel.