简体   繁体   中英

How to lineup Data from Column A to Data in Column B?

Column A is inventory that I should have. Column B is inventory I received.

I am missing a lot of inventory and have had to manually do this. What I want is the numbers in each column to match up & the numbers that are not present in B that are present in A to add a space in column B to show thats it's missing:

What I have:

在此处输入图片说明

What I want:

在此处输入图片说明

This is a pretty lightweight VBA routine that will do what you need:

Sub matchCells()
    Dim colARange As Range
    Dim colACell As Range

    'Change this to your Column A range size
    Set colARange = Sheet1.Range("A1:A5000") 

    'Iterate through each cell in your Column A Range
    For Each colACell In colARange.Cells

        'Check if the cell in Column A doesn't match the cell in Column B
        If Not (colACell.Value = colACell.Offset(0, 1).Value) Then

            'It doesn't match so shift Column B's cell down one
            colACell.Offset(0, 1).Insert Shift:=xlShiftDown
        End If

        'Now we loop again and we will continue shifting Column B down
        ' a cell until it matches. 

    Next
End Sub

在此处输入图片说明

You can try below formula on Column C... Should give you the result you need in Column C.

=IF(ISNA(VLOOKUP(A1,$B$1:$B$10,1,FALSE)),"",VLOOKUP(A1,$B$1:$B$10,1,FALSE))

$B$1:$B$10 is the Range of data (no of rows in column B)

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