|
将一个总表的内容,依据不同的筛选条件自动更新到指定的工作薄。
下面两个VBA能单独运行,但要运行两次,想两个合并到一起,点一次就能运行,不知道怎么改,试了很久各种报错。
麻烦哪位高手看下,谢谢!
第一个:
Sub Refresh()
Application.ScreenUpdating = False
Dim endrow As Long
Dim i As Long, j As Long
Dim r1 As Long, r2 As Long
r1 = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row
r2 = Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row
endrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To endrow
If Cells(i, "o") = "" Then
If Cells(i, "n") = "Completed" Then
r1 = r1 + 1
For j = 1 To 14
Sheet2.Cells(r1, j) = Cells(i, j)
Next
' Rows(i).Delete
Cells(i, "o") = "Exported"
ElseIf Cells(i, "n") = "" Then
r2 = r2 + 1
For j = 1 To 14
Sheet3.Cells(r2, j) = Cells(i, j)
Next
' Rows(i).Delete
Cells(i, "o") = "Exported"
End If
End If
Next
Application.ScreenUpdating = True
End Sub
第二个:
Sub Refresh1()
Application.ScreenUpdating = False
Dim endrow As Long
Dim i As Long, j As Long
Dim r1 As Long, r2 As Long
r3 = Sheet7.Cells(Sheet7.Rows.Count, "A").End(xlUp).Row
r4 = Sheet8.Cells(Sheet8.Rows.Count, "A").End(xlUp).Row
endrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To endrow
If Cells(i, "o") = "" Then
If Cells(i, "H") = "STEP3" Then
r3 = r3 + 1
For j = 1 To 14
Sheet7.Cells(r3, j) = Cells(i, j)
Next
' Rows(i).Delete
Cells(i, "o") = "Exported"
ElseIf Cells(i, "H") = "STEP4" Then
r4 = r4 + 1
For j = 1 To 14
Sheet8.Cells(r4, j) = Cells(i, j)
Next
' Rows(i).Delete
Cells(i, "o") = "Exported"
End If
End If
Next
Application.ScreenUpdating = True
End Sub
|
|