0

如何将我的 Excel 编码为 VBA?从右边开始,Target.Offset(0, -4).Value = 我不知道在 VBA 中怎么说:(Text(TODAY(), "MM") & Text(TODAY(), "DD") & Text(TODAY(), "yyyy")) & "-" . iVal

这是为了根据日期自动记录记录。这是整个代码:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 Then
    Application.EnableEvents = False
    Target.Offset(0, 2).Value = Date
    Target.Offset(0, 4).Value = "Open"


Dim iVal As Integer
iVal = Application.WorksheetFunction.CountIf(Range("H1:H5000"), Date)
    Target.Offset(0, -4).Value = (Text(TODAY(), "MM") & Text(TODAY(), "DD") & Text(TODAY(), "yyyy")) & "-" . iVal

    Application.EnableEvents = True
End If
End Sub
4

2 回答 2

1

格式化文本的函数是 FORMAT,today() 的函数是 Date。示例如下:

format(Date,"ddmmyyyy")

这应该可以解决您的问题=]我认为您的意思是

& iVal

而不是

. iVal 

在最后?

于 2013-07-19T18:13:54.937 回答
1

这对你有什么用....我假设列

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 Then
    Application.EnableEvents = False
    Target.Offset(0, 2).Value = Date
    Target.Offset(0, 4).Value = "Open"


**Dim iVal As Integer
iVal = Application.WorksheetFunction.CountIf(Range("H1:H5000"), Date)
    Target.Offset(0, -4).Value = Format(Date, "mmddyy") & "-" & Format(iVal, "000")**

    Application.EnableEvents = True
End If
End Sub
于 2013-07-19T18:21:58.917 回答