在Excel中匹配两个列表

我试图以最自动化的方式比较Excel中两个月的销售额(未来几个月会更快)

在这里输入图像说明

这个月的价值都是通过公式计算出来的,最后几个月会复制并粘贴到D:E中。 但是,正如您所看到的,有些客户上个月进行了购买,然后在本月没有(反之亦然)。 我基本上需要有所有的CustomerID的行匹配。 所以,举个例子来说吧:

在这里输入图像说明

任何人都可以想到一个很好的方法做到这一点,而不必手动做这一切? 谢谢

使用SUMIFS函数或VLOOKUP。 喜欢这个:

http://screencast.com/t/VTBZrfHjo8tk

你应该把你的整个客户名单放在一张表上,然后把每个月的相关数值加起来。 你所描述的devise将是一个噩梦,随着时间的推移,并没有任何用处。 我可以理解你希望看到像这样的客户,这就是为什么我build议SUMIFS。

这个选项只比较两列,我想你会想办法,首先我会添加date/月份,然后你可以添加下一个月的值:
在这里输入图像说明

那么你可以使用一个简单的枢轴在一段时间内看到更多的月份
在这里输入图像说明
任何情况下,如果你想格式化你的两列,你可以使用这个代码(你将更新与你的参考,我用你的IMG例子的date)

Sub OrderMachColumns() Dim lastRow As Integer Dim sortarray(1 To 2, 1 To 2) As String Dim x As Long, y As Long Dim TempTxt10 As String Dim TempTxt11 As String Dim TempTxt20 As String Dim TempTxt22 As String lastRow = Range("A3").End(xlDown).Row ' I use column A, same your example For x = 3 To lastRow * 2 Cells(x, 1).Select If Cells(x, 1) = "" Then GoTo B If Cells(x, 4) = "" Then GoTo A If Cells(x, 1) = Cells(x, 4) Then Else If Cells(x, 1).Value = Cells(x - 1, 4).Value Then Range(Cells(x - 1, 4), Cells(x - 1, 5)).Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove ElseIf Cells(x, 1).Value = Cells(x + 1, 4).Value Then Range(Cells(x, 1), Cells(x, 2)).Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Else sortarray(1, 1) = Cells(x, 1).Value sortarray(1, 2) = "Cells(" & x & ", 1)" sortarray(2, 1) = Cells(x, 4).Value sortarray(2, 2) = "Cells(" & x & ", 4)" For Z = LBound(sortarray) To UBound(sortarray) For y = Z To UBound(sortarray) If UCase(sortarray(y, 1)) > UCase(sortarray(Z, 1)) Then TempTxt11 = sortarray(Z, 1) TempTxt12 = sortarray(Z, 2) TempTxt21 = sortarray(y, 1) TempTxt22 = sortarray(y, 2) sortarray(Z, 1) = TempTxt21 sortarray(y, 1) = TempTxt11 sortarray(Z, 2) = TempTxt22 sortarray(y, 2) = TempTxt12 End If Next y Next Z Select Case sortarray(1, 2) Case "Cells(" & x & ", 1)" Range(Cells(x, 1), Cells(x, 2)).Select Case "Cells(" & x & ", 4)" Range(Cells(x, 4), Cells(x, 5)).Select End Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove End If End If A: Next x B: End Sub