现在我在用VBA做EXCEL中的统计工作,可是我现在我有一个问题,就是各列中都有四中不同的色的格子组成, 我想统计出每列中每种色中格子数;大伙有什么好的方法!请多多发言!

解决方案 »

  1.   

    Public Sub tongJiList()Dim varfontst As Variant
     
    Dim n As Integer, v As Integer, k As Integer, l As Integer, w As Integer
    For i = 2 To 16
      For j = 8 To 282
             If Cells(j, i).Interior.ColorIndex = 4 Then n = n + 1 '測試時間
             If Cells(j, i).Interior.ColorIndex = 3 Then v = v + 1 ' 忙時
             If Cells(j, i).Interior.ColorIndex = 6 Then k = k + 1 '重作時間
             If Cells(j, i).Interior.ColorIndex = 45 Then l = l + 1 '甩期時間
             If Cells(j, i).Interior.ColorIndex = -4142  Then w = w + 1  '空閑時間
         End If
        Next
        
        Sheet4.Activate
        Sheet4.Select
        Sheet4.Cells(i + 1, 4) = n: Sheet4.Cells(i + 1, 5).Value = v: Sheet4.Cells(i + 1, 6).Value = k: Sheet4.Cells(i + 1, 7).Value = l: Sheet4.Cells(i + 1, 8).Value = w: Sheet4.Cells(i + 1, 9) = m + n + v + k + l + w
         m = 0: n = 0: v = 0: k = 0: l = 0: w = 0
    Next
    End Sub大家可能有很多的方法,我是判断每个格子的是什么底色的,如果是这种色,就加一!
    感兴趣可以试试~~~~~