我一直在努力解决这个问题几个小时,并且一直碰壁。我非常接近,但有一些小细节错误。目前我在excel vba中使用=weeknum来动态创建一行并接收#NUM!错误。当我引用一个单元格时它似乎有效,但是当我手动输入一个日期时,我得到类型不匹配错误并改变其他错误。我使用的日期格式是 6/3/2013
非常感谢您的任何帮助,并感谢您的宝贵时间!
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