excel - Excel VBA:根据日期(单元格值)删除行并附加到另一个工作表
问题描述
我的脚本正在运行,但我仍然在 CDate(S) > 日期(类型不匹配错误 13)这一行上遇到错误。
我认为日期格式正确,但显然不是。
Private Sub CommandButton21_Click()
'ActiveSheet.Unprotect "password" 'Change password accordingly.
Dim x As Long
Dim iCol As Integer
Dim MaxRowList As Long
Dim S As String
Set wsSource = Worksheets("Sheet1")
Set wsTarget = Worksheets("Sheet2")
iCol = 1
MaxRowList = wsSource.Cells(Rows.Count, iCol).End(xlUp).Row
For x = MaxRowList To 1 Step -1
S = wsSource.Cells(x, 16)
If CDate(S) < Date Then
AfterLastTarget = wsTarget.Cells(Rows.Count, 1).End(xlUp).Row + 1
wsSource.Rows(x).Copy
wsTarget.Rows(AfterLastTarget).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
wsSource.Rows(x).Delete
End If
Next
Application.ScreenUpdating = True
'ActiveSheet.Protect "password" 'Change password accordingly.
MsgBox ("Update complete")
End Sub
解决方案
我认为你需要改变Dim S As Date
祝你好运
推荐阅读
- qt5 - QMake 使用 dll 构建静态库
- javascript - 使用 .map() 在 reactjs 中打印两个一组的值
- javascript - Check if a user input is NaN
- php - PHP end()函数没有在Laravel中获取结束数组项和对象键
- javascript - Flask - 在不重新加载的情况下更新表单
- azure-virtual-machine - 从 API Manager 服务访问虚拟机的规则
- spring-security - X509AuthenticationFilter 方法返回 null
- sql - 使用 Oracle12 中的合并技术在公用表中插入非重复值
- apache-spark - 使用 Spark Operator 在 Kubernetes 中启用多集群故障转移
- android - 无法连接到 Android 调试数据库,即使更改端口