用不完整的数据创build一个逐步值表

我无法绕过这个问题。

我有一个缺less查找值的表。

Price Company 1 Company 2 Company 3 $100 5 - 1 $200 2 9 - $300 6 - - $400 - 2 1 $500 4 - - 

我想用相邻单元格的值填写这些缺失的条目,所以我仍然可以以逐步的方式绘制它们。

 Price Company 1 Company 2 Company 3 $100 5 **9** 1 $200 2 9 **1** $300 6 **9** **1** $400 **6** 2 1 $500 4 **2** **1** 

逻辑是从上面的行取值,如果上面没有可能的行包含值,则从下面的行取下一个可能的值。 上面的例子说明了这一点。 数字的位置比确定用什么来填充单元格的实际数值要重要。

这应该让你开始。

 Sub Stepwise() 'get the worksheet With Worksheets("sheet1") 'get the block of data radiating out from A1 With .Cells(1, 1).CurrentRegion 'shift off the header row and right one column With .Cells.Resize(.Rows.Count - 1, .Columns.Count - 1).Offset(1, 1) 'get rid of hyphens .Replace what:=Chr(45), replacement:=vbNullString, lookat:=xlWhole 'optional - get rid of any non-numeric values On Error Resume Next .Value = .Value2 .SpecialCells(xlCellTypeConstants, xlTextValues) = vbNullString On Error GoTo 0 'shift one more row down - same number of columns With .Cells.Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0) 'make sure there are blank cells If Application.Count(.Cells) < .Cells.Count Then 'get the blank cells With .SpecialCells(xlCellTypeBlanks) .FormulaR1C1 = "=R[-1]C" End With .Value = .Value2 End If End With 'shorten by one row - same number of columns With .Cells.Resize(.Rows.Count - 1, .Columns.Count) 'make sure there are blank cells If Application.Count(.Cells) < .Cells.Count Then 'get the blank cells With .SpecialCells(xlCellTypeBlanks) .FormulaR1C1 = "=R[1]C" End With End If .Value = .Value End With End With End With End With End Sub 

如果逻辑不适用于更大的差距,然后尝试修改,并返回寻求帮助,如果你卡住了。

Stepwise_sample_data_before Stepwise_sample_data_after
逐步 采样 之前的数据逐步 采样之后的数据