我具有以下创建范围副本的内容。
Dim lastColumn As Long
lastColumn = wks.Cells(2, wks.Columns.Count).End(xlToLeft).Column
lastColumn = Application.Max(lastColumn + 1, wks.Columns("T").Column)
With wks.Range(Cells(2, 5), Cells(lastrow, 5)) ' This is the range I need to copy in my case
Dim columnOffset As Long
columnOffset = lastColumn - .Columns(1).Column
Call Timestamp(wks.Range(Cells(1, columnOffset)))
.Copy
.Offset(0, columnOffset).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End With
然后我调用以下函数在复制的单元格上方创建一个时间戳,但是在复制的单元格上方获得一个空单元格
Public Function Timestamp(Reference As Range)
If Reference.Value <> "" Then
Timestamp = Format(Now, "dd-mm-yyyy hh:mm:ss")
Else
Timestamp = ""
End If
End Function
我做错了什么? 谢谢
答案 0 :(得分:1)
您需要更新单元格,而不是从函数中返回值。使用现有代码尝试类似的操作
CreateMap<Category, CategoryViewModel>()
.ForMember(dest => dest.NumberOfExpenses, opt => opt.MapFrom(cat =>
cat => BankingAccountCategory.Select(bac => bac.Expenses)));
您可以简化此过程,不确定是否完全需要该功能,但这并不重要。类似的东西也应该起作用:
wks.Range(Cells(1, columnOffset)).value = Timestamp(wks.Range(Cells(1, columnOffset)))
答案 1 :(得分:0)
我将其更改为以下
If wks.Cells(1, lastColumn).Value = "" Then
wks.Cells(1, lastColumn).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
End If
所以我有以下内容
Dim lastColumn As Long
lastColumn = wks.Cells(2, wks.Columns.Count).End(xlToLeft).Column
lastColumn = Application.Max(lastColumn + 1, wks.Columns("T").Column)
With wks.Range(Cells(2, 5), Cells(lastrow, 5)) ' This is the range I need to copy in my case
Dim columnOffset As Long
columnOffset = lastColumn - .Columns(1).Column
If wks.Cells(1, lastColumn).Value = "" Then
wks.Cells(1, lastColumn).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
End If
.Copy
.Offset(0, columnOffset).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End With