![](/img/trans.png)
[英]Excel VBA : How to access (Referenced) Ranges from Formula in a Cell
[英]How can I write this cell-referenced Excel formula in VBA to use in MS Access: (b2-a1)
這是在Excel中執行的非常簡單的計算,但是我對如何使用不同記錄的表中的2個字段在Access中執行此操作感到困惑。 我需要一個應用程序來查找操作STOPTime和下一個STARTTime之間的差異。 任何幫助將不勝感激。 我是VBA的新手。
Sub samPle()
Dim startTime As Date
Dim endTime As Date
startTime = Time
'''Your Code
endTime = Time
Debug.Print DateDiff("n", startTime, endTime) ' difference in minutes
End Sub
有多種方法可以根據您的數據來解決問題,這使得發布有關SQL問題的數據非常重要。 例如:
表:
ID EventTime EventType
1 17/02/2013 08:52:00 start
2 17/02/2013 09:52:00 stop
3 17/02/2013 11:52:00 start
4 17/02/2013 15:52:00 stop
SQL:
SELECT a.id,
a.eventtime AS Start,
a.eventtype,
(SELECT TOP 1 eventtime
FROM times b
WHERE eventtype = "stop"
AND eventtime > a.eventtime
ORDER BY eventtime,
id) AS Stop,
Datediff("n", [start], [stop]) AS RunTime
FROM times AS a
WHERE (( ( a.eventtype ) = "start" ))
ORDER BY a.eventtime;
結果:
ID Start EventType Stop RunTime
1 17/02/2013 08:52:00 start 17/02/2013 09:52:00 60
3 17/02/2013 11:52:00 start 17/02/2013 15:52:00 240
重新評論
SELECT a.id,
a.eventtime AS Start,
a.eventtype,
(SELECT TOP 1 eventtime
FROM times b
WHERE eventtype = "stop"
AND eventtime > a.eventtime
ORDER BY eventtime,
id) AS Stop,
Datediff("n", [start], [stop]) AS RunTime,
(SELECT TOP 1 eventtime
FROM times b
WHERE eventtype = "start"
AND eventtime > a.eventtime
ORDER BY eventtime,
id) AS NextStart,
Datediff("n", [start], [nextstart]) AS StartDiff,
Datediff("n", [stop], [nextstart]) AS DownTime
FROM times AS a
WHERE (( ( a.eventtype ) = "start" ))
ORDER BY a.eventtime;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.