Please help, how to change the destination range to only be in the M2:V2 range.
Private Sub CommandButton2_Click()
Dim rng As Range, j As Variant
Dim StartV As Long, EndV As Long, i As Long
Dim k() As Long, Last_Row As Long
' Clear contents of the target range
ActiveSheet.Range("M2:M" & Range("M3").End(xlDown).Row).ClearContents
Last_Row = Range("A2").End(xlUp).Row
'Last_Row = Range("A2").End(xlRight).Row
ReDim k(0)
' Set range to B2:K2
Set rng = Range("B2:K2")
StartV = Range("B2")
EndV = Range("K2")
StartV = 0
EndV = 9
For i = StartV To EndV
On Error Resume Next
j = Application.Match(i, rng, 0)
If IsError(j) Then
k(UBound(k)) = i
ReDim Preserve k(UBound(k) + 1)
End If
Next i
' Output the missing values to M2:V2
Range("M2") = "Resul Missing values"
Range("M2:V" & UBound(k) + 1) = Application.Transpose(k)
End Sub
New contributor
SAM389 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.