Want to increment a Alphanumeric value in a range of cells [Closed]

Report
-
Posts
2758
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
June 17, 2021
-
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


1 reply

Posts
2758
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
June 17, 2021
462
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

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!