2013-04-05 98 views
0

早上好! 即時通訊學習VBA,看到餐飲部負責人在這裏寫的代碼How to perform a sumif using blank cells as a reference?,它工作正常,但在我需要實現的逆向過程。在我的電子表格中,計數從第一個非空白單元格開始,然後去除空白單元格直到達到下一個非空白單元格,然後在最後一個空白單元格中輸入總和(從第一個非空白直到最後一個空白細胞,然後從下一個非空白細胞重新開始)。 感謝循環非空白和空白單元格

00:21.6  10/1/2012 1:43  FALSE  00:21.6 
01:47.7  10/1/2012 2:13  FALSE  01:47.7 
00:56.7  10/1/2012 2:49  FALSE  
00:54.9  10/1/2012 3:43  
00:11.8  10/1/2012 3:43    2:34(00:56.7 +00:54.9+00:11.8) 
02:10.9  10/1/2012 3:46  FALSE  02:10.9  
01:05.4  10/1/2012 3:58  FALSE  
00:55.8  10/1/2012 4:53  
04:41.8  10/1/2012 4:52  
00:26.3  10/1/2012 4:58  
00:04.2  10/1/2012 4:58  
00:15.3  10/1/2012 4:59  
00:06.4  10/1/2012 4:57  
00:10.7  10/1/2012 4:56  
00:04.4  10/1/2012 4:56  
00:04.2  10/1/2012 4:57  
00:29.2  10/1/2012 4:57  
00:34.5  10/1/2012 4:56  
01:22.4  10/1/2012 4:55      (01:05.400:55.8+04:41.8+...+01:22.4) 

00:08.1  10/1/2012 4:55  FALSE  00:08.1 
03:20.9  10/1/2012 4:51  FALSE  03:20.9 
00:56.3  10/1/2012 5:42  FALSE  00:56.3 
02:23.1  10/1/2012 5:51  
01:20.6  10/1/2012 5:48  
00:09.8  10/1/2012 5:49  FALSE  03:53.5(i.e., 02:23.1+01:20.6+00:09.8) 
01:40.0  10/1/2012 7:47  FALSE  01:40.0 
01:13.4  10/1/2012 8:11  FALSE  01:13.4 
00:41.6  10/1/2012 9:49  FALSE  00:41.6 
01:08.1  10/1/2012 11:56  FALSE  01:08.1 
+0

第一列中的數據是什麼? '00:21.6'既不是時間也不是數字。 – 2013-04-05 13:33:12

+0

現在是時間00:21.6或00:21:00 – 2013-04-05 14:36:46

+0

或00:21:06但是相關的是代碼,它可能是時間或列 – 2013-04-05 16:19:21

回答

0

此代碼走下列,加,因爲它去,然後把答案爲它找到的第一個空白單元格。

Sub CountMeBlank() 

Dim varCounter As Variant 

Do Until ActiveCell.Value = "" 

    varCounter = varCounter + ActiveCell.Value 
    ActiveCell.Offset(1, 0).Select 

Loop 

ActiveCell.Value = varCounter 


'Grabs the formatting from the last cell as the data could be time or numeric. 
ActiveCell.Offset(-1, 0).Select 
Selection.Copy 
ActiveCell.Offset(1, 0).Select 
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ 
    SkipBlanks:=False, Transpose:=False 
Application.CutCopyMode = False 

'Then colours the cell red to show contrast 
ActiveCell.Font.Color = vbRed 

End Sub 

如果您需要一次循環所有數據,您需要以某種形式的循環包裝它。