我有一张充满数据的工作表,从A列到G列。
如何使用VBA宏:
如果C <>“ CLOSE”中的值和B中的值<19:00和> 00:00,则复制行(而不是整行,仅复制列A,B,C,D,E)。
编辑:
我尝试了此解决方案,但是运行它时,没有找到任何选定的单元格。
Dim r As Range, N As Long
Set r = Intersect(ActiveSheet.UsedRange, Range("B:C"))
N = Cells(Rows.Count, 2).End(xlUp).Row
For i = 1 To N
cc = Cells(i, 2).Value
dd = Cells(i, 3).Value
If cc >= "19:00" And cc < "00:00" And dd <> "Close" Then
ActiveSheet.Range(Cells(i, 1), Cells(i, 2), Cells(i, 3), Cells(i, 4), Cells(i, 5)).Select
End If
Next i
我已经尝试使用字母而不是数字来表示列(... Cells(i,A)代替Cells(i,1)),但是它不起作用。
谢谢。
答案 0 :(得分:0)
尝试以下代码:
Sub CopyRows()
Dim lastRow As Long, i As Long, time As Variant
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
For i = 1 To lastRow
If Cells(i, 3) = "CLOSE" Then GoTo SkipLoop
'extract just hour and see if it's less than 19
If CInt(Left(Cells(i, 2), 2)) < 19 Then GoTo SkipLoop
Range(Cells(i, 1), Cells(i, 5)).Select
SkipLoop:
Next
End Sub