0
我attemptinf寫(我第一次)的自定義功能,將基本循環通過一份報告,在未來的1,3,6個月之和機器的成本(ETC)Excel的自定義函數不正確地更新
的函數返回值,但是,這些值不正確,更有問題的包含自定義函數的單元格上的雙重更改使用自定義函數的周圍單元格的值。
,即時通訊處理的代碼是在這裏:
Option Explicit
Dim months As Integer 'a month is considered as 30 days
Dim cost As Long
Dim FleetData As Range
Dim rowCounter As Long
Dim lastRow As Long
Dim firstRow As Long
Dim component As Range
Dim dateOfAction As Range
Dim totalApprox As Range
Dim dateHorizon As Date 'Date to which the user wants to total the maintenance cost for
Private Function totalCosts(xMonths As Range)
'Dim totalCosts As Long
Application.Volatile
dateHorizon = Date + (30 * months)
firstRow = [A10].Row
rowCounter = firstRow
lastRow = Range("A65000").End(xlUp).Row
Set FleetData = [A10:S14]
If IsNumeric(xMonths.Value) Then months = xMonths.Value Else
If IsDate(xMonths.Value) Then months = (xMonths.Value - Date)/30
cost = 0
Do While rowCounter < lastRow
Set component = Range(Cells(rowCounter, 1), Cells(rowCounter, 19))
Set dateOfAction = Cells(rowCounter, 7)
Set totalApprox = Cells(rowCounter, 12)
If dateOfAction <= dateHorizon Then
cost = cost + totalApprox
End If
totalCosts = cost
rowCounter = rowCounter + 1
Loop
End Function
而且,即時通訊使用的數據是:
DateOfAction totalApprox
5/07/2014 $30,068.62
24/05/2005 $6,300.00
5/07/2012 $29,742.00
5/07/2012 $4,360.28
27/12/2012 $5,555.89
點擊一個細胞似乎遊移的值,但在沒有可識別訂購。
已經Google搜索,看起來here,但迄今沒有任何東西似乎解決了這個問題。
任何幫助將不勝感激!
我意識到我的代碼有多麼可怕。謝謝你的提醒。我試圖在UDF中付出很多努力,並且當我確實需要一個宏時嘗試使用一個函數。非常感謝您對最新回覆的提問和道歉 – BiGXERO