|
本帖最后由 marshall_yang 于 2014-11-3 20:42 编辑
各位高手:
附件里我能正常运行代码,可是当我把工作表里“当天出货明细”的内容清空后,并且鼠标停留在该该工作表中(“当天出货明细”)再次运行该代码,就会报错,不知是什么原因,请大家帮忙看看,谢谢
Sub 当天需出货明细()
Dim i As Integer
Dim rg As Range
j = Sheet1.UsedRange.Rows.Count
For i = 2 To j
If Cells(i, "G") = "2014-6-23" Then
If rg Is Nothing Then
Set rg = Cells(i, "G")
Else
Set rg = Union(rg, Cells(i, "G"))
End If
End If
Next i
rg.EntireRow.Copy Sheet2.[a2]
Sheet1.Range("1:1").Copy Destination:=Sheet2.[a1]
End Sub
- Sub 当天需出货明细()
- Dim i As Integer
- Dim rg As Range
- With Sheet1
- j = .UsedRange.Rows.Count
- For i = 2 To j
- If .Cells(i, "G") = "2014-6-23" Then
- If rg Is Nothing Then
- Set rg = .Cells(i, "G")
- Else
- Set rg = Union(rg, .Cells(i, "G"))
- End If
- End If
- Next i
- rg.EntireRow.Copy Sheet2.[a2]
- End With
- Sheet1.Range("1:1").Copy Destination:=Sheet2.[a1]
- End Sub
复制代码
|
|