PDA

View Full Version : [SOLVED] Sequence Function



saikrishna
11-23-2016, 11:03 PM
Hi All,

I'm trying a function to get sequence between 2 values. Below given example for better understand.

1st Value = A1245
2nd Value = A1257

When I give above values in 'AddNum' function. It should give 'A1245,A1246,A1247' as result.

Below given vba code wrote by myself and i requesting you, please help on this.



Public x As Double
Function AddNum(Val1 As Variant, Val2 As Variant)
If Val1 = "" Or Val2 = "" Then
Exit Function
Else
x = -(Right(Val1, 4) - Right(Val2, 4))
End If
Dim myary As Variant
ReDim myary(x) As Variant
For y = LBound(myary) To UBound(myary)
Z = Right(Val1, 4) + y
myary(y) = Left(Val1, 2) & Z
ActiveCell.Offset(0, y + 1).Value = myary(y)
Next y
End Function

mana
11-24-2016, 05:13 AM
Option Explicit

Function AddNum(Val1 As String, Val2 As String)
Dim i As Long
Dim n As Long

If Val1 = "" Or Val2 = "" Then Exit Function

For i = CLng(Mid(Val1, 2)) To CLng(Mid(Val2, 2))
n = n + 1
ActiveCell.Offset(0, n).Value = Left(Val1, 1) & i
Next i

End Function