gpt4 book ai didi

excel - 如何显示错误信息和停止宏

转载 作者:行者123 更新时间:2023-12-04 21:19:52 25 4
gpt4 key购买 nike

我是编码 VBA 的新手。我想添加一个弹出框,其中显示“找不到今天的日期”消息,如果在 K 列中找不到今天的日期,则停止宏。不知道该怎么做以及代码应该在哪里。

' Find the last row on the count sheet and the next row on the archieve sheet

lastRow = countSheet.Cells(countSheet.Rows.count, "K").End(xlUp).Row
nextRow = archieveSheet.Cells(countSheet.Rows.count, "K").End(xlUp).Row + 1

' Look at all rows in the count sheet
For thisRow = 1 To lastRow

' Check if column K contains today's date
If countSheet.Cells(thisRow, "K").Value = Date Then

' Copy the entire row to the archieve sheet
countSheet.Cells(thisRow, "K").EntireRow.Copy Destination:=archieveSheet.Cells(nextRow, "A")

' Move to the next row on the archieve sheet
nextRow = nextRow + 1
End If
Next thisRow

最佳答案

在开头添加一些简单的代码将使一切变得简单

If Application.WorksheetFunction.CountIf(countsheet.Range("K:K"), Date) = 0 Then
MsgBox "Today's Date Not Found"
Exit Sub
End If

关于excel - 如何显示错误信息和停止宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55522036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com