我对VBA非常陌生,并且一直在上个礼拜自学。我承担了一项对我来说可能有点复杂的任务。Excel VBA类型与If函数不匹配
我有一个列A - AE 的文档我需要通过此文档并将信息移动到单独的工作表上,具体取决于它是什么。 我现在试图在移动信息之前使用需要匹配2个要求的IF语句。我可以获取每个单独的需求,但不能同时处理类型不匹配错误。
我不知道我做错了什么。任何帮助都感激不尽。
Sub copyrows()
Dim Test As Range, Cell As Object
Set Test = Range("G2:Z4000") 'Substitute with the range which includes your True/False values
For Each Cell In Test
If IsEmpty(Cell) Then
Exit Sub
End If
If Cell.Value = "Refund" And "Commission" Then
Cell.EntireRow.Copy
Sheet3.Select 'Substitute with your sheet
ActiveSheet.Range("A65536").End(xlUp).Select
Selection.Offset(1, 0).Select
ActiveSheet.Paste
End If
Next
End Sub
为什么'Cell'是一个'Object'?我会把它变成一个'Range',因为这就是你使用它的原因。尽管'Object' *可能会起作用,但我相信'Range'更好。 – BruceWayne