Question: In the list bellow it's an Excel Range, I need to choose two numbers equals to 100 so in return I want to get (30 & 70) or (60 & 40). Can I do that dynamically 

I use Excel but if you have any suggestion of other programs it would be fine.

> 
> A  
> 
>  30  
> 
>  60   
> 
>  70  
> 
>  40
> 
> 
>

Answer: 
here the code without verification of duplicated pairs

```
Sub test()
    Dim x&, lastR&, oCell1 As Range, oCell2 As Range, Key As Variant
    Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
    x = 1
    lastR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    For Each oCell1 In ActiveSheet.Range("A1:A" & lastR)
        For Each oCell2 In ActiveSheet.Range("A1:A" & lastR)
            If oCell1.Value + oCell2.Value = 100 Then
                Dic.Add x, "(" & oCell1.Value & " & " & oCell2.Value & ")"
                x = x + 1
            End If
        Next
    Next
    For Each Key In Dic
         Debug.Print Key, Dic(Key) 'output in immediate window all possible
    Next
    MsgBox Dic(WorksheetFunction.RandBetween(1, Dic.Count))
End Sub

```

here the result

![enter image description here](https://i.stack.imgur.com/XdRPx.jpg)

here the code with verification of duplicated pairs

```
Sub test()
    Dim x&, S$, S2$, check%, lastR&, oCell1 As Range, oCell2 As Range, Key As Variant
    Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
    x = 1
    lastR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    For Each oCell1 In ActiveSheet.Range("A1:A" & lastR)
        For Each oCell2 In ActiveSheet.Range("A1:A" & lastR)
            check = 0
            If oCell1.Value + oCell2.Value = 100 Then
                S = "(" & oCell1.Value & " & " & oCell2.Value & ")"
                S2 = "(" & oCell2.Value & " & " & oCell1.Value & ")"
                For Each Key In Dic
                    If Dic(Key) = S Or Dic(Key) = S2 Then
                        check = 1: Exit For
                    End If
                Next
                If check = 0 Then
                    Dic.Add x, S
                    Debug.Print x, Dic(x)
                    x = x + 1
                End If
            End If
        Next
    Next
    MsgBox Dic(WorksheetFunction.RandBetween(1, Dic.Count))
End Sub

```

here the result

![enter image description here](https://i.stack.imgur.com/qXmGe.jpg)
With your data in **A1** thru **A4,** try this macro:

```
Sub JustKeepTrying()
    Dim N As Long, M As Long, wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    Do
        N = wf.RandBetween(1, 4)
        M = wf.RandBetween(1, 4)
        If N <> M Then
            If Cells(M, 1) + Cells(N, 1) = 100 Then
                MsgBox Cells(M, 1).Address & vbTab & Cells(M, 1).Value & vbCrLf _
                     & Cells(N, 1).Address & vbTab & Cells(N, 1).Value
                Exit Sub
            End If
        End If
    Loop
End Sub

```