VBA – Loop Through a String

Associated Files Download Links


You can perform logic on, or return individual characters from a string in VBA by looping through the string.

Loop Through Each Character in a String

The following is an example of looping through a string using a For…Next Loop, and returning each character in a msgbox.

The Len Function counts the total number of characters in the string. So the expression

will loop through each letter in the string.

Loop Through Each Character in a String – Alternative

Read Every Character in a String
: This example reads every character in a string from left to right and returns the result in a message box. It makes use of the Mid function.

Read Every Word in a String

This example reads every word in a string from left to right and returns the result in a message box. It makes use of the Split function.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

[convertkit form=4869294]


<<Return to VBA Examples

Did you find this VBA tutorial useful? Then share it with your friends and colleagues:

You may also like some of this related content...

VBA has many string functions that will allow you to manipulate and work with text
In VBA, you can compare two strings using the StrComp function. In this tutorial, you
Reverse a String of Text with VBA The VBA Routine below allows the user to
INSTR Function You can use the Instr Function in VBA to test if a string
Return nth Word in String of Text The following function will find the nth word
Ads