Want to increment a Alphanumeric value in a range of cells

Closed
Ram Gengadar - May 2, 2016 at 08:38 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - May 2, 2016 at 11:42 AM
Hello,

I have Alphanumeric value in range of cells example from B2 to b28
number will be like H000000000000100 I want to increment the last four values alone using excel macro's
Can anyone help me solving this please
thanks in advance


Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
May 2, 2016 at 11:42 AM
Hi Ram,

Try the following code:
Sub RunMe()
Dim mVal1 As String, mVal2, x As Integer
mVal1 = Left(Range("B2").Value, 12)
mVal2 = Right(Range("B2").Value, 4)
x = 2
Do
    x = x + 1
    mVal2 = mVal2 + 1
    If Len(mVal2) = 4 Then
        Range("B" & x) = mVal1 & mVal2
    Else
        Range("B" & x) = mVal1 & "0" & mVal2
    End If
Loop Until x = 28
End Sub

Best regards,
Trowa
0