Pinterest Pixel

Remove Characters at the Start Using Macros In Excel

Bryan
Want to quickly truncate the first number of characters of your choosing? Excel Macros can remove characters at the start of your selection of text!
Remove Characters at the Start Using Macros In Excel | MyExcelOnline Remove Characters at the Start Using Macros In Excel | MyExcelOnline

Make sure your Excel has the Developer Tab enabled following this tutorial.

I explain how you can do this below step by step!

What does it do?

Removes the number of characters at the start as specified by the user

Copy Source Code:

</p>
<p>Sub RemoveCharactersAtTheStart()</p>
<p>Dim range As Range<br />
Dim num As Integer</p>
<p>Get the &lt;a href=&quot;https://www.myexcelonline.com/blog/remove-character-from-string/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;characters to be removed from&lt;/a&gt; the user<br />
num = InputBox(&amp;amp;quot;Input the number of characters to remove at the start&amp;amp;quot;, &amp;amp;quot;Num of characters&amp;amp;quot;)</p>
<p>'Loop through all of the text<br />
For Each range In Selection<br />
'Use Right to remove the first x characters<br />
range = Right(range, Len(range) - num)<br />
Next range</p>
<p>End Sub</p>
<p>

Final Result: 

Insert Time Range Using Macros In Excel

Exercise Workbook:

Remove Characters at the Start Using Macros In Excel | MyExcelOnline

Download excel workbookRemove-Characters-at-the-Start.xlsm


This is the text that we want to modify. We want to remove the first 2 characters of these Part Numbers:

Insert Time Range Using Macros In Excel

STEP 1: Go to Developer > Code > Visual Basic

Remove Characters at the Start Using Macros In Excel | MyExcelOnline

 

STEP 2: Paste in your code and Select Save. Close the window afterwards.

Insert Time Range Using Macros In Excel

 

STEP 3: Let us test it out!

Open the sheet containing the data. Go to Developer > Code > Macros

Remove Characters at the Start Using Macros In Excel | MyExcelOnline

 

Make sure your part numbers and macro are selected. Click Run.

Insert Time Range Using Macros In Excel

We want to remove the first 2 characters. Type in 2 and Click OK.

Insert Time Range Using Macros In Excel

With just one click, the first 2 characters are now all removed!

Insert Time Range Using Macros In Excel

 

How to Remove Characters at the Start Using Macros In Excel

 

101 Macros Book

If you like this Excel tip, please share it
Remove Characters at the Start Using Macros In Excel | MyExcelOnline
Bryan

Bryan Hong is an IT Software Developer for more than 10 years and has the following certifications: Microsoft Certified Professional Developer (MCPD): Web Developer, Microsoft Certified Technology Specialist (MCTS): Windows Applications, Microsoft Certified Systems Engineer (MCSE) and Microsoft Certified Systems Administrator (MCSA).

He is also an Amazon #1 bestselling author of 4 Microsoft Excel books and a teacher of Microsoft Excel & Office at the MyExecelOnline Academy Online Course.

See also  Add Date In Header Using Macros In Excel

Get Video Training

Advance your Microsoft Excel & Office Skills with the MyExcelOnline Academy!

Dramatically Reduce Repetition, Stress, and Overtime!
Exponentially Increase Your Chances of a Promotion, Pay Raise or New Job!

Learn in as little as 5 minutes a day or on your schedule.

Learn More!

Share to...