如果选择了正确的状态和名称,我将尝试复制并粘贴A:E行。例如,如果状态在A列中显示为“进行中”,或在B列中显示名称为“ Thomas Xiong”,则它将复制该行并将其粘贴到另一个名为“ WIPTX”的工作表中。然后,在工作表“ WIPTX”中,它将复制并将该行粘贴到列I:M下的下一个可用行下。以下几列是针对工作表WIPTX的。
Status Columns
Assigned A:E
Accepted F:J
In Progress K:O
On Hold P:T
Completed U:Y
Cancelled Z:AD
我已经研究了一段时间,并测试了许多代码以查看其是否有效。我尝试的最后一个代码在“ In Progress”情况下给了我一个语法错误。
Sub Hello()
Dim lRow As Long, cRow As Long, j As Long
With Sheets("WIPdata")
lRow = .Range("A800").End(xlUp).Row
' another method of finding last row in Column A (skipping blank cells in the middle)
lRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For j = lRow To 1 Step -1
cRow = Sheets("WIPTX").Range("A800").End(xlUp).Row
Select Case .Range("J" & j).Value
Case "Assigned"
.Range("A" & j & ":E" & j).Copy Destination:=Sheets("WIPTX").Cells(Sheets("WIPTX").Cells(Sheets("WIPTX").Rows.Count, "A").End(xlUp).Row + 1, "A")
Case "Accepted"
.Range("A" & j & ":E" & j).Copy Destination:=Sheets("WIPTX").Cells(Sheets("WIPTX").Cells(Sheets("WIPTX").Rows.Count, "E").End(xlUp).Row + 1, "E")
Case "In Progress"
.Range("A" & j & ":E" & j).Copy Destination:=Sheets("WIPTX").Range("A" & cRow + 1).Cells(Sheets("WIPTX").Rows.Count, "I").End(xlUp).Row + 1, "I")
Case "On Hold"
.Range("A" & j & ":E" & j).Copy Destination:=Sheets("WIPTX").Range("A" & cRow + 1).Cells(Sheets("WIPTX").Rows.Count, "M").End(xlUp).Row + 1, "M")
Case "Completed"
.Range("A" & j & ":E" & j).Copy Destination:=Sheets("WIPTX").Range("A" & cRow + 1).Cells(Sheets("WIPTX").Rows.Count, "Q").End(xlUp).Row + 1, "Q")
Case "Cancelled"
.Range("A" & j & ":E" & j).Copy Destination:=Sheets("WIPTX").Range("A" & cRow + 1).Cells(Sheets("WIPTX").Rows.Count, "U").End(xlUp).Row + 1, "U")
End Select
Next
End With
End Sub
答案 0 :(得分:0)
Sub InProgress()
Dim idxprogress As Integer
idxprogress = 3
Dim idxassigned As Integer
idxassigned = 3
Dim idxonhold As Integer
idxonhold = 3
Dim idxcancelled As Integer
idxcancelled = 3
Dim idxaccepted As Integer
idxaccepted = 3
Dim idxcompleted As Integer
idxcompleted = 3
Sheets("WIPdata").Activate
For Each cell In Range("A2:A55")
Sheets("WIPdata").Activate
Select Case cell.Value
Case "In Progress"
Sheets("WIPdata").Range("B2:F2").Copy
Sheets("WIPTX").Activate
Sheets("WIPTX").Range(Cells(idxprogress, 11), Cells(idxprogress, 15)).PasteSpecial
idxprogress = idxprogress + 1
Case "Assigned"
Sheets("WIPdata").Range("B2:F2").Copy
Sheets("WIPTX").Activate
Sheets("WIPTX").Range(Cells(idxassigned, 1), Cells(idxassigned, 5)).PasteSpecial
idxassigned = idxassigned + 1
Case "On Hold"
Sheets("WIPdata").Range("B2:F2").Copy
Sheets("WIPTX").Activate
Sheets("WIPTX").Range(Cells(idxonhold, 16), Cells(idxonhold, 20)).PasteSpecial
idxonhold = idxonhold + 1
Case "Cancelled"
Sheets("WIPdata").Range("B2:F2").Copy
Sheets("WIPTX").Activate
Sheets("WIPTX").Range(Cells(idxcancelled, 26), Cells(idxcancelled, 30)).PasteSpecial
idxcancelled = idxcancelled + 1
Case "Accepted"
Sheets("WIPdata").Range("B2:F2").Copy
Sheets("WIPTX").Activate
Sheets("WIPTX").Range(Cells(idxaccepted, 6), Cells(idxaccepted, 10)).PasteSpecial
idxaccepted = idxaccepted + 1
Case "Completed"
Sheets("WIPdata").Range("B2:F2").Copy
Sheets("WIPTX").Activate
Sheets("WIPTX").Range(Cells(idxcompleted, 21), Cells(idxcompleted, 25)).PasteSpecial
idxcompleted = idxcompleted + 1
Case Else
End Select
Next cell
End Sub