简体   繁体   中英

the listing of values in a column that correspond to a specific value in another column in excel

the source data is in the following format

    A   B
    1   0
    2   0
    4   1
    5   0
    6   0
    8   1

I originally intended to list the missing items in the column A but since that did not quite work out for me, I intend to achieve the same thing via the method I will propose now.

What I want is a list that goes

    C
    3
    7

essentially giving me the missing numbers of the sequence by using the values provided in the column B. But basically any solution that would give me the values listed under column C would be very appreciated.

It should be noted that I am working with a large list so that manual filtering and such are not preferable.

In cell G4 enter an address you want to look in, for example A2:A5 and then use the array formula below. The only assumption is that the list of numbers should begin from 1 . I know it looks crazy, the formula. This formula has to be applied to range, so select a range, then go to address bar paste this formula and press CTRL + SHIFT + ENTER . In this particular case the range has to be in column shape.

I left the formula as not formatted text, so it was easier to copy.

=IF(INT(SQRT(MMULT((IF(TRANSPOSE(MMULT(INDIRECT(G4),1+0*TRANSPOSE(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))))=MMULT(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))),1+0*TRANSPOSE(ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))),0,ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))^2),1+0*ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))/COUNTA(INDIRECT(G4))))=SQRT(MMULT((IF(TRANSPOSE(MMULT(INDIRECT(G4),1+0*TRANSPOSE(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))))=MMULT(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))),1+0*TRANSPOSE(ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))),0,ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))^2),1+0*ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))/COUNTA(INDIRECT(G4))),SQRT(MMULT((IF(TRANSPOSE(MMULT(INDIRECT(G4),1+0*TRANSPOSE(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))))=MMULT(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))),1+0*TRANSPOSE(ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))),0,ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))^2),1+0*ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))/COUNTA(INDIRECT(G4))),"")

The formula could be read as

=IF(INT(A)=A,A, "")

where A is

SQRT(MMULT((IF(TRANSPOSE(MMULT(INDIRECT(G4),1+0*TRANSPOSE(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))))=MMULT(ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))),1+0*TRANSPOSE(ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))),0,ROW(INDIRECT("1:"&MAX(INDIRECT(G4)))))^2),1+0*ROW(INDIRECT("1:"&COUNTA(INDIRECT(G4)))))/COUNTA(INDIRECT(G4)))

If column B is not needed (it can be computed from A ), assuming that you have the data on sheet named worksheet1 , the VBA sub that writes all the missing values to column C is the following:

Sub worksheet1c()
    'this contains the position in column A
    Dim i As Integer
    'this contains the position in column C
    Dim j As Integer
    'the numbers from 1
    Dim number As Integer

    'initialization
    i = 1
    j = 1
    number = 1

    'check all numbers in column A from row 2
    Do While Sheets("worksheet1").Cells(i, 1).Value <> ""
        'if there is a difference between number and the value in cell write them to column C
        Do Until number = Sheets("worksheet1").Cells(i, 1).Value
            Sheets("worksheet1").Cells(j, 3).Value = number
            j = j + 1
            number = number + 1
        Loop
        i = i + 1
        number = number + 1
    Loop
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM