我一直在努力解決這個問題幾個小時,並繼續打牆。我非常接近,但有小的細節錯誤。目前,我在excel vba中使用= weeknum來動態創建一行並接收#NUM!錯誤。它似乎工作時,我引用一個單元格,但當我手動輸入日期時,我得到類型不匹配的錯誤,並改變其他錯誤。我使用的日期格式是6/3/2013Excel財政周計算器
任何幫助非常感謝,並感謝您的時間!
Sub Macro2()
Dim xDate As Double
Dim ReturnType As Integer
TotalRowCount = ThisWorkbook.Sheets("sap").UsedRange.Rows.count
Set entryDateRange = ThisWorkbook.Sheets("sap").Range("G2:G" & TotalRowCount)
'my attempt at setting the datatype for the row, I dont think this is needed, but was one solution I saw
'Range("M2:M" & TotalRowCount).NumberFormat = "@"
'create a collumn to hold the fiscal week output
ThisWorkbook.Sheets("sap").Range("M1") = "FW"
For Each test In entryDateRange
CurrentRow = test.Row
fw_calc = Application.Evaluate("=WEEKNUM(G" & CurrentRow & "," & ReturnType & ")")
' In place of (G" & CurrentRow.. etc I would prefer to use test if possible
Worksheets("sap").Cells(CurrentRow, 13) = fw_calc
Next test
End Sub
工作就像一個魅力,謝謝安迪! – Tyler