In this article, we are going to create user defined function to find out the missing number in a range through VBA in Microsoft Excel.
User Defined Function: Microsoft Excel allows you to create your own function as per the requirement, we call it User Defined Function. And, we can use User Defined functions like other functions work in Excel.
Let’s take an example to understand:-
We have a data in which we have values for every code ID, and we want to check the missing value in between 1 to 99, if in the range values are missing then which values all missing and if all values are available then result should be all values are available.
We will write the VBA code to find out the missing numbers follow below given steps:
Function Missing_Number(Myrange As Range) Dim Number(1 To 99) As Integer On Error Resume Next For Each Cell In Myrange Number(Cell.Value) = 1 Next On Error GoTo 0 Missing_Number = "Missing: " For I = 1 To 99 If Not Number(I) = 1 Then Missing_Number = Missing_Number & I & "," End If Next I If Len(Missing_Number) = 9 Then Missing_Number = Left(Missing_Number, Len(Missing_Number) - 2) End If End Function
In this way, we can return the missing values from the data for every row by using VBA in Microsoft Excel
We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at firstname.lastname@example.org
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.