Board logo

標題: [發問] 加入條件修訂程式碼 [打印本頁]

作者: b9208    時間: 2015-2-10 16:57     標題: 加入條件修訂程式碼

各位先進您好
如下程式碼,今加入一條件,當M欄儲存格值 = WORK時才計算統計。
敬請先進們指導,如何修改程式碼。
非常感謝

With Sheets("工料")
If .[D6].End(xlDown).Row = .Rows.Count Then MsgBox "無資料": Exit Sub
For Each A In .Range(.[D6], .[D65536].End(xlUp)).SpecialCells(xlCellTypeConstants)
Ar = Split(A, "+")
   For Each C In Ar
      MyStr = C & "," & Left(A.Offset(, 3), 8) & "," & A.Offset(, 8)
      dic1(MyStr) = Split(MyStr, ",")
   Next
Next
End With
作者: rouber590324    時間: 2015-2-11 08:31

DEAR SIR
  加入如下試試

X = Application.WorksheetFunction.CountIf(Range("M1:M65536"), "WORK")
If X - 1 >= 0 Then
  
End If
作者: b9208    時間: 2015-2-11 11:22

回復 2# rouber590324

您好
應插入於程式碼那位置?
謝謝您的協助
作者: lpk187    時間: 2015-2-11 12:03

本帖最後由 lpk187 於 2015-2-11 12:05 編輯

Private Sub Worksheet_Change(ByVal Target As Range)
n = Target.Row
If Target = Cells(n, "M") Or Cells(n, "M") = "work" Then
    Cells(n, "N") = Application.Sum(Range("I" & n & ":K" & n))
Else
    End
End If
End Sub
試試類似這方式看看是不是你想要的
這Sub,是只要改變儲存格就會去執行想要的動作
作者: rouber590324    時間: 2015-2-11 14:01

With Sheets("工料")
If .[D6].End(xlDown).Row = .Rows.Count Then MsgBox "無資料": Exit Sub

X = Application.WorksheetFunction.CountIf(Range("M1:M65536"), "WORK")
If X - 1 >= 0 Then

For Each A In .Range(.[D6], .[D65536].End(xlUp)).SpecialCells(xlCellTypeConstants)
Ar = Split(A, "+")
   For Each C In Ar
      MyStr = C & "," & Left(A.Offset(, 3), 8) & "," & A.Offset(, 8)
      dic1(MyStr) = Split(MyStr, ",")
   Next
Next

ENDIF
End With




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)