2013-12-19 3 views
0
Function LinkedSheet(rgCell As Range) As Worksheet 
'Returns the worksheet that the cell formula references 
'Returns nothing if there's no formula 
    Dim strFormula As String 

    strFormula = rgCell.Cells(1, 1).Formula 

    If (strFormula <> "") Then 
     'Return the sheet that this range is linked to 
    End If 
End Function 

이 기능을 완료하는 데 도움을 줄 수있는 사람이 있습니까? 이 싯다 르트 나라 얀 패주에 대응하여, 내가 이전셀 수식에서 참조하는 워크 시트를 얻는 방법

Function LinkedSheet(rgCell As Range) As Worksheet 
'Returns the worksheet that the cell formula references 
'Returns nothing if there's no formula 
    Dim strFormula As String, sheetName As String 

    strFormula = rgCell.Cells(1, 1).Formula 

    If (strFormula <> "") Then 
     'Return the sheet that this range is linked to 
     sheetName = Mid(strFormula, 2, InStr(1, strFormula, "!") - 2) 
     Set LinkedSheet = ThisWorkbook.Worksheets(sheetName) 
    End If 
End Function 
을 시도 :이 편집

"시트 1"과 같은 이름의 공간이 시트에 내부 링크, 외부 링크 및 링크 작동한다는 것을 명심하십시오

이름에 공백이있는 시트의 경우 실패합니다. 그러나 나는 문제를 다루는 더 효율적이고 효율적인 방법이 있어야한다고 느꼈기 때문에 나는 이것을 게시하는 것을 꺼려했다. 나는 내가가는 방향과 같은 방향으로 사람들의 생각을 터뜨리고 싶지 않았다.

+2

시도해 보셨습니까? 코드를 묻는 질문은 해결하려는 문제에 대한 최소한의 이해를 보여 주어야합니다. 시도한 해결책, 실패한 이유 및 예상되는 결과를 포함하십시오. 참고 항목 : [Stack Overflow question checklist] (http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) –

+1

http://www.vbaexpress.com/forum/showthread.php?19348 -solved-Splitting-all-in-a-formula & p = 142863 # post142863 –

+0

잠깐 생각한 것처럼 : 수식에'!'의 위치를 ​​찾으십시오. 문자열 – Barranka

답변

1

는 여기에 내가 그것으로 완전히 만족하지 않아요 내 솔루션

Function LinkedSheet(rgCell As Range) As Worksheet 
'Returns the worksheet that the cell formula references 
'Returns nothing if there's no formula 
    Dim strFormula As String, sheetName As String 

    strFormula = rgCell.Cells(1, 1).Formula 

    If (strFormula <> "") Then 
     'Return the sheet that this range is linked to 
     If (InStr(1, strFormula, "='") = 0) Then 
      sheetName = Mid(strFormula, 2, InStr(1, strFormula, "!") - 2) 
     Else 
      sheetName = Mid(strFormula, 3, InStr(1, strFormula, "!") - 4) 
     End If 
     Set LinkedSheet = ThisWorkbook.Worksheets(sheetName) 
    End If 
End Function 

입니다. 나는 여전히 더 나은 접근법이있을 수 있다고 생각하지만 이것은 효과적이다.

+0

@andy 시트 이름에 "Andy 's Sheet"와 같은 아포스트로피가 있으면 실패하지 않겠습니까? – Ben

+0

정확합니다. 내 의견을 삭제했습니다. FWIW, 엑셀은 시트 이름의 아포스트로피 (다른 아포스트로피)를 자동으로 이스케이프하므로 간단히 바꾸면 작동하지 않습니다. –

관련 문제