제게 도와 줄 수 있습니까? 다른 통합 문서의 시트를 참조하려고하지만 함수가 # VALUE를 반환합니다! 오류.VBA : 다른 통합 문서의 시트를 참조하여 닫을 수도 있고 닫을 수도 있습니다.
'Set variable for other Workbook
Dim oh As Workbook
'This filepath may need to be changed if the file is moved
Set oh = Workbooks.Open("C:\Filepath\Filename.xlsx")
'Set variable for cs sheet in the other workbook
Dim cs As Worksheet
Set cs = oh.Worksheets("cs")
전체 코드는 여기에 있습니다 : :
Option Explicit
Function WLR(CN, Ct)
'Turn off screen updating
Application.ScreenUpdating = False
''Change this to refer to sheet in other workbook later.
''For now, it refers to the cs sheet on this workbook
'Dim cs As Worksheet
'Set cs = ThisWorkbook.Sheets("cs")
'Set variable for other Workbook
Dim oh As Workbook
'This filepath may need to be changed if the file is moved
Set oh = Workbooks.Open("C:\Filepath\Filename.xlsx")
'Set variable for cs sheet in the other workbook
Dim cs As Worksheet
Set cs = oh.Worksheets("cs")
'Get Info from cs sheet
Dim i As Integer
i = 2
With cs
Do While i <= .Rows.Count 'Check you haven't exceeded the limit
If .Cells(i, 2) <> "" Then 'Check the cell isn't blank
If .Cells(i, 2) = CN Then 'Check if course name is in list
Exit Do 'Exit loop with i set to correct row if CN is found
End If
Else
WLR = "" 'Return blank if course name not found
'Turn on screen updating
Application.ScreenUpdating = True
Exit Function
End If
i = i + 1
Loop
'Turn on screen updating
Application.ScreenUpdating = True
'Set Result
WLR = .Cells(i, 6)
End With
End Function
내가 다른 워크 시트를 참조에 대한 비트를 주석이 통합 문서의 시트를 복사하려고 나는 그것이 오류의 원인이되는이 비트 생각 그리고이 통합 문서 내의 cs 시트에 대한 약간의 주석을 달았습니다.이 작업은 성공적 이었지만 실제로 다른 통합 문서를 참조해야합니다. 어떤 아이디어? 나는 여기에서 수색했고 시트 색인을 사용하는 것과 같은 많은 것을 시도했다. 그러나 나는 정말로 지금 붙이게된다.
편집 : 함수가 충돌하지 않고 VALUE #! 오류. 문제는 내가 시트를 참조하려고하는 곳이라고 생각합니다. 이전에 시도했지만 통합 문서를 참조하기 만하면 오류가 반환되지 않았습니다.
목표는 무엇입니까? 범위 또는 범위 값에 대한 참조를 반환합니까? BTW, 함수에 "Ct"매개 변수를 사용하고 있습니다.이 매개 변수는 사용되지 않습니다. – user3598756
내 목표는 범위 값을 반환하는 것입니다. 나는 이것을 기반으로 Ct 매개 변수가 앞으로 사용될 것입니다. 나는 더 이상 나가기 전에이 비트가 먼저 작동하도록하고 싶습니다. – JeniD