我正在编写一个代码,该代码通过一个给定的单元格范围,每个循环都有一个。如果这些调用不满足带有“for each”的 if 语句,我需要将该单元格的范围写在另一张纸上。例如:单元格 A20 和 A36 不符合,所以我想在另一张纸上写 A20 和 36。这样,我将列出所有需要注意的单元格。下面是我的代码:
r = 5
Set sht1 = Sheets("DataSheet")
Set sht2 = Sheets("DiscrepancyReport")
On Error GoTo DiscrepancySheetError
sht2.Select
On Error GoTo DataSheetError
sht1.Select
On Error GoTo 0
lastr = ActiveSheet.range("A1").Offset(ActiveSheet.Rows.Count - 1, 0).End(xlUp).Row
lastr = lastr - 1
'Column 1: WP
Set colrg = range("A3:A" & lastr)
For Each cell In colrg
If (cell.Value) = 6.01 Or (cell.Value) = 6.03 Or (cell.Value) = 3.04 Or (cell.Value) = 6.27 Then
Else
'## The following line makes no sense but i wrote it so you understand what i want to do
currentcell.range.Copy Destination:=sht2.range("A" & r)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Not a valid WP"
r = r + 1
End If
Next
提前谢谢!