2017-01-11 1 views
0

함수에 두 개의 범위 인수를 전달 중입니다. 하나는 정상적으로 작동하지만 두 번째는 컴파일 오류가 발생합니다. 여기인수를 인수로 전달할 때 VBA 컴 플라이 오류가 발생했습니다.

I 함수를 호출하고 - 여기

Set SourceRange = Sheets("QueryResult").Range("QueryResult") 
Set DestinationRange = Sheets("TradeUnderlyingCptyWWRTemplate").Range("CounterpartyName") 
Call PopulateDetails(23, SourceRange, DestinationRange, 2, 8) 

그리고이되는 함수 : 그러나

Function PopulateDetails(SourceColumns As Integer, Srce As Range, Destination As Range, DestinationColums As Integer, DestinationRows As Integer) 

Dim CellName As String 
Dim a, b, i As Integer 

For b = 0 To DestinationRows - 1 
    For a = 0 To DestinationColums - 1 

     On Error GoTo Err: 
     Sheets("TradeUnderlyingCptyWWRTemplate").Select 
     Destination.Offset(b, a).Select 
     CellName = Destination.Offset(b, a).Name.Name 

     For i = 0 To SourceColumns - 1 
      If (Destination.Offset(b, a).Name.Name = Srce.Offset(0, i).Value And Destination.Offset(b, a).Value = "") Then 
       Destination.Offset(b, a).Value = Srce.Offset(1, i).Value 
       Exit For 
      End If 
     Next 
Err: 
     On Error Resume Next 
     Err.Clear 
     CellName = "" 
    Next 
Next 

End Function 

, 그것은 컴파일주고있다 오류 : 강조 SourceRange

byref argument type mismatch

코드.

4 개의 인수 (소스 인수 삭제) 만 사용하도록 함수를 변경하면 올바르게 작동합니다.

+1

에 해당

Dim SourceRange, DestinationRange As Range 

Dim SourceRange As Range Dim DestinationRange As Range 

로 변경해야 HTTP : //stackoverflow.com/q/28238292/11683) 어딘가에서 [ByRef 인수 유형 불일치 "오류 VB6]의 가능한 복제본이됩니다 (http : // stackove rflow.com/q/25316331/11683). – GSerg

+0

예, 맞습니다. 코드 시작 부분에 Range로 Dim SourceRange, DestinationRange가 있습니다. 해당 줄을 제거해도 여전히 같은 오류가 발생합니다. –

+0

그런 다음 두 링크를 모두 누르십시오. – GSerg

답변

0

당신은 당신이 [Range`으로`희미한 SourceRange, DestinationRange를 (있다고 가정 그렇지 않으면

Dim SourceRange As Variant 
Dim DestinationRange As Range 
+0

고마워 톤 @neelsg 완벽하게 작동했습니다. –

관련 문제