我有一張「數據」表。有了這張表,我正在查看K列。如果它是紅色的,那麼我將提取完整的行並將它們複製到另一張「延遲」表中。使用單元格值將數據從一張紙複製到另一張
我遵循以下代碼。代碼沒有任何錯誤,但是,它只是複製4行紅色,而我有12行。
任何人都可以幫助我找到我錯在哪裏,我需要什麼變化?
Sub delay()
Dim cell As Range
Dim nextrow As Long
Dim a As Double
Application.ScreenUpdating = False
a = Application.WorksheetFunction.CountA(Sheets("Data").Range("K:K"))
For Each cell In Sheets("Data").Range("K5:K" & a)
If cell.DisplayFormat.Interior.Color = vbRed Then
nextrow = Application.WorksheetFunction.CountA(Sheets("Delayed").Range("K:K"))
Rows(cell.Row).Copy Destination:=Sheets("Delayed").Range("A" & nextrow + 1)
End If
Next
Application.ScreenUpdating = False
End Sub
使用'CountA'的基本原理是什麼? K列保證是非空的,直到列中最後使用的單元格爲止? – YowE3K
@ YowE3K不,不保證 – Jenny
那麼你想用'CountA'實現什麼? 'CountA'計算K列中有多少非空單元,然後用它來生成''K5:K「&a'和'」A「&nextrow + 1',即某種範圍。爲什麼數字或非空單元格確定您將要處理的最後一行? – YowE3K