감사. 주로 "set ws"섹션. 각 "set"명령의 오른쪽에 나는 그 페이지로 전송되어야하는 문자열을 넣습니다. 그게 다 맞습니까? 그렇다면 데이터를 가져올 때 Worksheets로 가져옵니다 ("Feb - Monitor")? 이것이 G 열의 문자열을 검색하는 기본 페이지입니까? 이 모든 것이 정확하다면 이것은 당신을 위해 일해야합니다. 통합 문서의 복사본을 만들어 복사본에서 먼저 시도하십시오. VBA 편집기에서 일반 모듈을 만들어이 모듈에 붙여 넣습니다. G 열의 문자열을 기반으로 행을 복사하여 해당 페이지에 붙여 넣습니다. 다른 페이지로 복사 한 후 워크 시트 ("Feb - Monitor")에서 해당 행을 제거하려면 down에서 nextRow = 2의 주석 처리를 제거하십시오.
Sub Macro1()
'Feb - Monitor - Anything keyed in as RT, T, RE, RJ
'is moved to the first sheet Pending -
'Anything keyed in as DA or I moves to this sheet Accepted -
'Anything keyed in as AC moves to this sheet. Released -
'Anything keyed in as RL moves to this sheet.
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Dim lastRow As Long
Dim nextRow As Long
Dim myArray() As Variant
Set ws1 = Worksheets("Feb - Monitor") ' RT, T, RE, RJ
Set ws2 = Worksheets("Pending") ' DA, I
Set ws3 = Worksheets("Accepted") ' AC
Set ws4 = Worksheets("Released") ' RL
lastRow = ws1.Range("G65536").End(xlUp).Row
myArray = ws1.Range("G2:G" & lastRow)
For i = LBound(myArray) To UBound(myArray)
If InStr(1, myArray(i, 1), "T") > 0 And InStr(1, myArray(i, 1), "RT") = 0 Or _
InStr(1, myArray(i, 1), "RT") > 0 Or InStr(1, myArray(i, 1), "RE") > 0 Or _
InStr(1, myArray(i, 1), "RJ") > 0 Then
' These need to stay on Worksheets("Feb - Monitor") so we do nothing
' The reason I added this loop is in case I misunderstood your need
' This loop is not necessary if we are'nt moving them
End If
If InStr(1, myArray(i, 1), "DA") > 0 Or InStr(1, myArray(i, 1), "I") > 0 Then ' send to "Pending"
nextRow = ws2.Range("G65536").End(xlUp).Row + 1
ws1.Rows(i + 1).Copy Destination:=ws2.Range("A" & nextRow)
End If
If InStr(1, myArray(i, 1), "AC") > 0 Then ' send to "Accepted"
nextRow = ws3.Range("G65536").End(xlUp).Row + 1
ws1.Rows(i + 1).Copy Destination:=ws3.Range("A" & nextRow)
End If
If InStr(1, myArray(i, 1), "RL") > 0 Then ' send to "Released"
nextRow = ws4.Range("G65536").End(xlUp).Row + 1
ws1.Rows(i + 1).Copy Destination:=ws4.Range("A" & nextRow)
End If
Next i
'*********************************************
' The following code deletes all rows on worksheets("Feb - Monotor)
' that are not RT, T, RE, RJ
' You can uncomment it if you want to do that
'nextRow = 2
'For i = LBound(myArray) To UBound(myArray)
' nextRow = nextRow + 1
' If InStr(1, myArray(i, 1), "DA") > 0 Or InStr(1, myArray(i, 1), "I") > 0 _
' Or InStr(1, myArray(i, 1), "AC") Or InStr(1, myArray(i, 1), "RL") > 0 Then
' nextRow = nextRow - 1
' Debug.Print i, myArray(i, 1), nextRow
' ws1.Rows(nextRow).Delete Shift:=xlUp
' End If
'Next i
Set ws1 = Nothing
Set ws2 = Nothing
Set ws3 = Nothing
Set ws4 = Nothing
End Sub
왜 모든 열이 비어 있습니까? 1 번 열의 필드 이름조차 없습니까? –