[英]Formula to copy certain rows to a new sheet in excel
我正在尋找一個公式,它將根據某些標准將行從一個工作表復制到另一個工作表(具體來說,是否突出顯示該行)。 怎么會這樣做呢?
我最后只使用了VBA。 我必須在開頭使用是/否單元格來指定是否突出顯示一行,以便每當有人更改值時它都會自動更新。
Sub Autosort()
Application.ScreenUpdating = False
Sheets(2).Select
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear
Sheets(3).Select
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear
Sheets(1).Select
FinalColumn = Cells(1, 1).End(xlToRight).Column
FinalRow = 1
For x = 1 To FinalColumn
thisRow = Cells(Rows.Count, x).End(xlUp).Row
If thisRow > FinalRow Then
FinalRow = thisRow
End If
Next x
For x = 2 To FinalRow
IsCompleted = Cells(x, 1).ValueThen
If IsCompleted = "Yes" Then
Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = xlColorIndexNone
Cells(x, 1).Resize(1, FinalColumn).Copy
Sheets(2).Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets(1).Select
ElseIf IsCompleted = "No" Then
Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = 6
Cells(x, 1).Resize(1, FinalColumn).Copy
Sheets(3).Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets(1).Select
Else
Cells(x, 1).Value = "No"
Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = 6
Cells(x, 1).Resize(1, FinalColumn).Copy
Sheets(3).Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets(1).Select
End If
Next x
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.