2011-08-31 3 views
1

Excel에서 예약 된 시간 동안 Tree Traversal을 만들려고합니다. 나는 각 1006 개의 셀을 2 개의리스트로 가지고있다. 첫 번째는 전임자이고 두 번째는 후임입니다. 여러 결과를 표시하는 함수 집합을 사용하려고합니다. 예를 들어 3을 입력하면 작업 3의 모든 후임자를 나열해야합니다. 지금까지 내가 함께 온 코드입니다 : 내가 입력 전임자가 올바른 후계자를 표시하지 않습니다 그러나EXCEL - 목록에서 값을 찾아 해당 값을 여러 개 반환합니다.

=IF(ISERROR(INDEX($A$1:$B$1006,SMALL(IF($A$1:$A$1006=$E$3,ROW($A$1:$A$1006)),ROW(1:1)),2)),"NO",INDEX($A$1:$B$1006,SMALL(IF($A$1:$A$1006=$E$3,ROW($A$1:$A$1006)),ROW(1:1)),2)) 

. 나를

+0

으로 워크 시트에 호출 수식을 사용하고 문제를 설명하기위한 몇 가지 샘플 데이터 라인 - 감사합니다! – MikeD

답변

0

당신은 수식 join 값 (또는 적어도, 내가 그것을 할 수있는 쉬운 방법을 볼 수 없습니다) 할 수없는 도움이 될 수 있습니다 누구를위한

은 사전에 감사합니다.

당신은 절차 (빠르지 만 더 방해)를 호출 할 수 있습니다 :

Option Explicit 

Sub Proc_ListPre() 
Dim rData As Range, lLastrow As Long, i As Integer 
Dim aValues() As Variant 
Dim sFilter As String, sRes As String 

'Ask for the value to filter to the user 
sFilter = InputBox("Which predecessor do you want to analyse?", "Please type the predecessor you want") 
If Len(sFilter) = 0 Then Exit Sub 

'Define the range 
'either use UsedRange (if only columns A and B are used) 
'Set rData = ActiveSheet.UsedRange 
'or use End(xlUp) if not 
lLastrow = ActiveSheet.Range("a65536").End(xlUp).Row 
Set rData = ActiveSheet.Range("A1:B" & lLastrow) 
'Filter the predecessor with the criteria given in arg 
rData.AutoFilter Field:=1, Criteria1:=sFilter 

'Find the last row of the filtered data 
lLastrow = ActiveSheet.Range("a65536").End(xlUp).Row 
aValues = ActiveSheet.Range("A2:B" & lLastrow).Value 
'Join the 2nd column of the array 
'Join(WorksheetFunction.Index(aValues, 0, 2), ";") 'note that this doesn't work because index returns a 2D array 
'Workaround to join the 2nd column 
For i = 1 To UBound(aValues, 1) 
    If Len(CStr(aValues(i, 2))) > 0 Then 
     sRes = sRes & aValues(i, 2) & ";" 
    End If 
Next 
sRes = Left(sRes, Len(sRes) - 1) 
MsgBox sRes 

ActiveSheet.AutoFilterMode = False 
End Sub 

또는 당신이 테이블 헤더를 추가 할 수 있습니다 =ListPre(mypredecessor)

Function ListPre(ByVal sFilter As String) 
Dim rData As Range, lLastrow As Long, i As Integer 
Dim aValues() As Variant 
Dim sRes As String 

'Define the range 
'either use UsedRange (if only columns A and B are used) 
'Set rData = ActiveSheet.UsedRange 
'or use End(xlUp) if not 
lLastrow = ActiveSheet.Range("a65536").End(xlUp).Row 
Set rData = ActiveSheet.Range("A1:B" & lLastrow) 
aValues = ActiveSheet.Range("A2:B" & lLastrow).Value 

'Join the 2nd column of the array 
'Join(WorksheetFunction.Index(aValues, 0, 2), ";") 'note that this doesn't work because it returns a 2D array 
'Workaround to join the 2nd column 
For i = 1 To UBound(aValues, 1) 
    If Len(CStr(aValues(i, 2))) > 0 And CStr(aValues(i, 1)) = sFilter Then 
     sRes = sRes & aValues(i, 2) & ";" 
    End If 
Next 
sRes = Left(sRes, Len(sRes) - 1) 
ListPre = sRes 
End Function 
관련 문제