你怎么能find一个大数字网格中最大的差距?

你好,我有一个excel工作表,其中包含一个巨大的价值网格,我想find最大的数字差距(任何数字,不一定是两个相邻的)。 我已经在这里看到了单列数据的解决scheme,但是我有一个巨大的网格,我几乎可以肯定的是,唯一值的数量大于现代excel中的最大行数,所以将它们合并到一个列中将无法工作。 有关如何使这项工作甚至有点有效的想法?

有一些假设是有用的,

  • 每列不包含空白或重复
  • 每列按升序排列
  • 不是所有的列都是相同的长度(实际上它们可能会有很大的不同)
  • 最大的差距可能很容易在两个不相邻的小区之间

公式和VBA方法都赞赏。

我想你应该循环遍历所有的列,并计算这样的最大的差距(我希望这个效果很好,我目前没有Excel,所以我只是写在这里,如果有任何错误出现评论,我会纠正我的码):

Sub LargestGap() Dim RowCount as Double, ColumnCount as Double, i as Double, j as Double, maxgap as Double ' largest gap Dim lgc as string ' for performance Application.Screenupdating=False ' this is just a sample set your columncount to the max columns ColumnCount = 20 maxgap=0 For i=1 to ColumnCount j=0 do until Cells(i,j+1)="" If Cells(i,j)<>Cells(i,j+1) then If (Cells(i,j+1)-Cells(i,j)) > maxgap then maxgap=(Cells(i,j+1)-Cells(i,j)) lgc=Cells(i,j+1).address End if End if j=j+1 Loop Next i Application.Screenupdating=True ' the messagebox will tell you the adress of the largest gap's cell (the first in the bigger) msgbox(lgc) End Sub