VBA를 사용하여 특정 시트 그룹이 다른 시트의 다른 셀 그룹과 일치하는지 확인하고 싶습니다. 내 경우에는 lastName, firstName
세포가 일치하는지 알아야합니다. 필자가 생각해 낸 솔루션에서 첫 번째 테이블을 반복하여 직원 이름을 얻었습니다. 그런 다음 두 번째 테이블을 반복하면서 직원 이름을 가져옵니다. 그런 다음 두 사람이 일치하는지 확인합니다. 이 방법은 비용이 너무 많이 들고 너무 오래 걸립니다. 이 작업을 수행하는 더 좋은 방법이 있습니까?다른 시트의 열 셀이 다른 셀과 동일한 지 찾기
내 첫 번째 테이블에는 6 개의 행이 있고 두 번째 테이블에는 100 개 이상의 행이 포함될 수 있습니다. 너무 많은 시간이 낭비됩니다.
전체 열을 검색하여 성이 먼저 일치하는지 확인하고, 일치하면 첫 번째 이름이 일치하는지 확인하려고했지만 다시 한 번 동일한 성 ...
여기까지 내가 지금까지 가지고있는 것입니다. 내가 더 조건문이없는 알고
For i = 2 To managerRows 'Looping through the Managers Table
empFirst = managerSheet.Cells(i, 1)
empLast = managerSheet.Cells(i, 2)
empName = (empLast & ", " & empFirst)
For j = 3 To assignRows 'Looping through the Assignments table
empLastAssign = assignSheet.Cells(i, 4)
empFirstAssign = assignSheet.Cells(i, 5)
empNameAssign = (empLastAssign & ", " & empFirstAssign)
'MsgBox (empNameAssign)
...
Conditional statement comparing names
...
Next j
Next i
, 난이 방법이 최선이 아니다 알고 있기 때문에 그것을 쓰는 귀찮게하지 않았다.
두 번째 시트 이름을 데이터베이스에서 읽고 다른 열과 성 및 이름으로 유지하기 때문에 두 번째 시트 이름을 연결하는 다른 열을 추가 할 수 없습니다. 어쨌든, 두 번째 시트에 다른 열을 추가하지 않고 이라는 이름을 연결할 수있는 방법이 있습니까? 그런 식으로 찾으시겠습니까? 말이 돼?
Find
내가 잘못하지 않으면 한 열만 보입니다. 두 가지로 볼 수 있습니까?
UPDATE 내가 마지막 이름의 첫 번째 발생을 얻을 수있어
아닌 다른 사람. 일치시킬 다른 입력란을 추가했습니다. 이제는 일치시킬 세 개의 필드가 있습니다. Last Name
, First Name
및 Project Name
. 지금까지, 내 코드는 첫 번째 발생 만 찾아서 거기에 머물러 있습니다. 루핑 순서가 잘못되었다고 생각합니다.
여기까지 제가 지금까지 있습니다.
For i = 2 To managerRows 'Looping through the Managers Table
empLast = managerSheet.Cells(i, 1)
empFirst = managerSheet.Cells(i, 2)
empName = (empLast & ", " & empFirst)
projectName = managerSheet.Cells(i, 3)
managerLast = managerSheet.Cells(i, 4)
managerFirst = managerSheet.Cells(i, 5)
managerName = (managerLast & ", " & managerFirst)
Set findRow = assignSheet.Range(assignSheet.Cells(3, 4), assignSheet.Cells(assignRows, 4)) 'Set a range to look for Last Name
Set c = findRow.Find(empLast, LookIn:=xlValues) 'Find matching Last Name if it exists
If Not c Is Nothing Then 'Last Name found
Do Until c Is Nothing 'Is this in the wrong place?
If Cells(c.Row, 5) = empFirst Then 'If first name matches
If Cells(c.Row, 10) = projectName Then 'If project name matches. We found them
MsgBox ("Found: " & empLast & ", " & empFirst & ": Project: " & projectName & " : in: " & c.Row)
End If
End If
Set c = findRow.FindNext(c) 'Is this is the wrong place?
Loop
End If
Set c = Nothing 'Is this in the wrong place?
Next i
내 새 루프는 'Is this in the wrong place?
입니다.
업데이트 2 :
해결 나는 성공적으로 find
및 findNext
를 사용하여 세 개의 열을 필터링했다. 좋은 대답 덕분에. 완성 된 버전을 게시합니다. 나는 발견 된 다음 링으로 가기 위해서 다른 필터를 추가해야했다. find
을 사용하여 세 개의 열에서 필터링에 대한 명확한 답이 없기 때문에 다른 사람들도이 정보를 얻을 수 있기를 바랍니다.
For i = 2 To managerRows 'Looping through the Managers Table
empLast = managerSheet.Cells(i, 1)
empFirst = managerSheet.Cells(i, 2)
empName = (empLast & ", " & empFirst)
projectName = managerSheet.Cells(i, 3)
managerLast = managerSheet.Cells(i, 4)
managerFirst = managerSheet.Cells(i, 5)
managerName = (managerLast & ", " & managerFirst)
'Focus Below this
Set findRow = assignSheet.Range(assignSheet.Cells(3, 4), assignSheet.Cells(assignRows, 4)) 'Set a range to look for Last Name
Set c = findRow.Find(empLast, LookIn:=xlValues) 'Find matching Last Name if it exists
If Not c Is Nothing Then 'Last Name found
Do Until c Is Nothing
If Cells(c.Row, 5) = empFirst Then 'If first name matches
If Cells(c.Row, 10) = projectName Then 'If project name matches. We found them
MsgBox ("Found: " & empLast & ", " & empFirst & ": Project: " & projectName & " : in: " & c.Row)
Set c = Nothing
Else
Set c = findRow.FindNext(c)
End If
Else
Set c = findRow.FindNext(c)
End If
Loop
End If
Next i
당신은'WorksheetFunction.Vlookup' – JamesFaix
당신이 "큰"시트에 데이터를 정렬 할 수 있겠지? (BTW : 100+ 행은 큰 행 번호가 전혀 없습니다!) – user3598756