VBA – Get All Numbers in a Text String & Incresae by One – Excel Macro
The following procedure will take any numbers within text and increase them by 1.
For Example:
For20Example51Text will transform into For21Example52Text
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Sub UpNumbersByOne() cell = "YOUR16STRING1HERE10" Dim v As Variant endresult = "" With CreateObject("VBScript.RegExp") .Pattern = "(\d+|\D+)" .Global = True v = Split(Mid(.Replace(cell, "|$1"), 2), "|") For Each num In v If IsNumeric(num) = True Then num = num + 1 End If endresult = endresult & num Next num End With Debug.Print endresult End Sub |
Posted by Excel Instructor:
http://www.houstoncomputerclasses.com/excel-classes/
