返回列表 上一主題 發帖

[發問] 如何用INPUTBOX輸入收單日期,跑出每個處方日期的數量加總,並以MSGBOX顯示

本帖最後由 GBKEE 於 2011-5-25 08:13 編輯

回復 2# luhpro
樓主希望 INPUTBOX輸入收單日期,跑出每個處方日期的數量加總
  For iI = 2 To iRow
    oD(CStr(Cells(iI, 1))) = oD(CStr(Cells(iI, 1))) + Val(Cells(iI, 3))
  Next iI
這段程式碼是每一處方日期的數量加總

TOP

  1. Sub ex()
  2. Set d = CreateObject("Scripting.Dictionary")
  3. Set d1 = CreateObject("Scripting.Dictionary")

  4. myday = CDate(InputBox("輸入日期", , Date))
  5. For Each a In Range([D2], [D65536].End(xlUp))
  6.   If a = myday Then d(a.Offset(, -3) & "") = d(a.Offset(, -3) & "") + a.Offset(, -1)
  7. Next
  8. For Each ky In d.keys
  9.    d1(ky & ":" & d(ky)) = ""
  10. Next
  11. MsgBox Join(d1.keys, Chr(10))
  12. End Sub
複製代碼
學海無涯_不恥下問

TOP

樞紐的方式我不會, 所以就試著用比較普通的方式來達成 :
Sub nn()
  Dim sStr$, sDate$
  Dim iRow%, iI%
  Dim vDate
  Dim oD As Object

  Set oD = CreateObject("Scripting.Dictionary")
  iRow = [A65535].End(xlUp).Row
  For iI = 2 To iRow
    oD(CStr(Cells(iI, 1))) = oD(CStr(Cells(iI, 1))) + Cells(iI, 3)
  Next iI
  vDate = InputBox("請輸入要查詢的收單日期 : ", "輸入收單日期")
  For iI = 2 To iRow
    If Trim(CStr(Cells(iI, 4))) = Trim(CStr(vDate)) Then
      If sDate <> CStr(Cells(iI, 1)) Then
        sStr = sStr + Chr(10) + CStr(Cells(iI, 1)) + " : " + CStr(oD(CStr(Cells(iI, 1))))
        sDate = CStr(Cells(iI, 1))
      End If
    End If
  Next iI
  MsgBox "收單日期 : " + vDate + " 的數量" + sStr
End Sub

TOP

        靜思自在 : 虛空有盡.我願無窮,發願容易行願難。
返回列表 上一主題