메인 컨텐츠로 가기

Excel의 목록에서 두 숫자의 가능한 모든 합계를 찾는 방법은 무엇입니까?

여기에 숫자 목록이 있다고 가정하면 아래 스크린 샷과 같이이 목록에서 두 숫자의 가능한 모든 합계를 찾을 수 있습니까? Excel에는이 작업을 해결할 수있는 기본 제공 기능이 없습니다. 이제이를 처리하기위한 VBA 코드를 소개합니다.
두 숫자의 가능한 모든 합을 doc 1

Find all possible sums of two numbers in a list with VBA code

Find all possible combinations of two lists with List All Combinationsgood idea3


Find all possible sums of two numbers in a list with VBA code

목록에서 두 숫자의 가능한 모든 합계를 찾으려면 VBA 코드 아래에서 신청할 수 있습니다.

1. 프레스 Alt + F11 표시하는 키 Microsoft Visual Basic for Applications 창.

2. 클릭 Insert > Module, 복사하여 아래 코드를 모듈에 붙여 넣으십시오.

VBA: List all possible sums of two numbers in a list

Sub Combinations()
'UpdatebyExtendoffice20180628
    Dim xRgArr
    Dim xNum As Long
    Dim I, J, K As Long
    Dim xTemp As Double
    Dim xRg As Range
    Dim xRgCount As Long
    Dim xDic As New Dictionary
    On Error Resume Next
    Set xRg = Application.InputBox("Select a list (one column):", "KuTools for Excel", Selection.Address, , , , , 8)
    If (xRg Is Nothing) Or (xRg.Count = 1) Then Exit Sub
    xRgCount = xRg.Count
    K = 1
    ReDim xRgArr(1 To xRgCount)
    For Each xCell In xRg
      xRgArr(K) = xCell.Value
      K = K + 1
    Next
    K = 0
    For I = 1 To xRgCount
        For J = I + 1 To xRgCount
            xTemp = xRgArr(I) + xRgArr(J)
            If Not xDic.Exists(xTemp) Then
                xDic.Add CDbl(xTemp), CStr(xTemp)
                K = K + 1
            End If
        Next
    Next
    Range("C1").Resize(xDic.Count, 1) = Application.WorksheetFunction.Transpose(xDic.Keys)
End Sub

두 숫자의 가능한 모든 합을 doc 2

3. 클릭 Tools > References, 팝업 대화 상자에서 Microsoft Scripting Runtime 확인란의 선택을 취소합니다.

두 숫자의 가능한 모든 합을 doc 3 문서 화살표 오른쪽 두 숫자의 가능한 모든 합을 doc 4

4. 클릭 OK 대화 상자를 닫으려면 F5 코드를 실행하기 위해 가능한 합계를 찾기 위해 목록을 선택하라는 대화 상자가 나타납니다.
두 숫자의 가능한 모든 합을 doc 5

5. 클릭 OK이면 목록에있는 두 숫자의 가능한 모든 합계가 C 열에 나열됩니다.
두 숫자의 가능한 모든 합을 doc 6

Tip: 코드 문자열 Range ( "C1"). Resize (xDic.Count, 1)에서 결과를 배치 할 필요에 따라 C1을 다른 셀로 변경할 수 있습니다.


Find all possible combinations of two lists with List All Combinations

아래 스크린 샷과 같이 두 목록의 가능한 모든 조합을 찾거나 나열하려면 List All Combinations ~의 유용성 Kutools for Excel 너에게 호의를 베풀 수있다.
두 숫자의 가능한 모든 합을 doc 7

Excel 용 Kutools, 이상과 300 편리한 기능으로 작업이 더 쉬워집니다. 

1. 클릭 Kutools > Insert > List All Combinations.
두 숫자의 가능한 모든 합을 doc 8

2. 에서 List All Combinations 대화 상자에서 선택 버튼을 클릭하여 결합 할 첫 번째 목록을 선택합니다.
두 숫자의 가능한 모든 합을 doc 9

3. 클릭 Add 목록을 추가하려면 Combinations list 안내
두 숫자의 가능한 모든 합을 doc 10

4. 2 단계와 3 단계를 반복하여 두 번째 목록을 Combinations list.
두 숫자의 가능한 모든 합을 doc 11

5. 그런 다음 Ok 조합 결과를 배치 할 셀을 선택합니다.
두 숫자의 가능한 모든 합을 doc 12

6. 클릭 OK. 가능한 모든 조합이 셀에 나열되었습니다.
두 숫자의 가능한 모든 합을 doc 13

Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations