第一篇文章。我有一个excel工作簿,如果一行处于活动状态并且列F中有一个值(日期),那么我无法弄清楚如何编码,然后填充下一个可用的行和列。我查了一下如果Range,IsError,If Goto,我只是不确定在当前代码中的位置。我在网上找到的任何东西似乎都没有用,或者我只是没有使用正确的语法。
With ws
irow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 0
On Error Resume Next
ws.Cells(irow, 1).Value = Application.Index(Range("C2:C500"), Application.Match(Range("A1").Value, Range("B2:B500"), 0))
ws.Cells(irow, 2).Value = Application.Index(Range("D2:D500"), Application.Match(Range("A1").Value, Range("B2:B500"), 0))
On Error GoTo 0
End With
n = Application.CountIf(ws.Columns(1), ws.Cells(irow, 1).Value)
If n = 0 Then
nr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 0
If nr = 2 And ws.Range("A2") = vbEmpty Then
nr = 1
End If
ws.Range("A" & nr) = ws.Cells(irow, 1).Value
ws.Range("B" & nr) = ws.Cells(irow, 2).Value
ws.Range("E" & nr) = Now()
ws.Range("E" & nr).NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"
ElseIf n > 0 Then
nr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 0
If ws.Cells(nr, 5).Value = ws.Cells(irow, 1).Value Then
nc = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.Cells(5, nc) = Now()
ws.Cells(5, nc).NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"
Else
Set bcr = ws.Columns(1).Find(ws.Cells(irow, 1).Value, LookAt:=xlWhole)
nc = ws.Cells(bcr.Row, Columns.Count).End(xlToLeft).Column + 1
ws.Cells(bcr.Row, nc) = Now()
ws.Cells(bcr.Row, nc).NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"
End If
End If