2014-08-29 2 views
2

디버그 도와주세요 : 런타임 오류 '438'개체가이 속성 또는 메서드 난엑셀 VBA : 런타임 오류 '438'개체가이 속성 또는 메서드를 지원하지 않습니다

을 지원하지 않습니다 확실하지 왜 내 기능의 ConvertToStdDateFormat (InputRange로 범위) 범위를 수락하지 않는 'ThisRange'

여기 아래

201301 201401  201301 201401 
201302 201402  201302 201402 
201303 201403  201303 201403 
201304 201404  201304 201404 
201305 201405  201305 201405 

코드

처럼 내 입력이 어떻게 표시되는지를 보여줍니다 (범위는 범위 개체 자체에 저장되어있는 위치와 ThisRange.Worksheet에서 참조 할 수있는 워크 시트를)
Sub trythis() 
Dim ThisRange As Range 
Dim MonthYear_array As Variant 
start_date_row = 1 
end_date_row = 12 

With ActiveSheet 
    Set ThisRange = .Range(Cells(start_date_row, 1), Cells(end_date_row, 2)) 
    MonthYear_array = .Range(Cells(start_date_row, 4), Cells(end_date_row, 5)).Value 
End With 

Call ConvertToStdDateFormat(ActiveSheet.Range(Cells(start_date_row,1), Cells(end_date_row, 2))) 
Call ConvertToStdDateFormat(ActiveSheet.ThisRange) 
End Sub 


Public Function GetMonthYearFormatted(InputDate) 
'InputDate should be in the format "201401" i.e. year(2014)month(01) 
    IPString = CStr(InputDate) 
    monthval = CInt(Right(IPString, 2)) 
    yearval = CInt(Left(IPString, 4)) 
    opDate = DateSerial(yearval, monthval, 1) 
    OPFormatDate = Month(opDate) & "-" & Year(opDate) 
    GetMonthYearFormatted = OPFormatDate 
End Function 

Function ConvertToStdDateFormat(InputRange As Range) 
    Dim temp_array As Variant 
    temp_array = InputRange 
    For colsC = 1 To UBound(temp_array, 2) 
     For rowsC = 1 To UBound(temp_array, 1) 
      temp_array(rowsC, colsC) = GetMonthYearFormatted(temp_array(rowsC, colsC)) 
     Next rowsC 
    Next colsC 
    InputRange.Resize(UBound(temp_array, 1), UBound(temp_array, 2)) = temp_array 
    ConvertToStdDateFormat = Null 
End Function 

답변

2

그냥

Call ConvertToStdDateFormat(ThisRange) 

하여 라인

Call ConvertToStdDateFormat(ActiveSheet.ThisRange) 

를 교체하고 코드가 작동합니다 .

디버깅을 쉽게하려면 모든 모듈을 Option Explicit으로 시작하는 것이 좋습니다. 이렇게하면 모든 변수를 명시 적으로 적용합니다 (즉, Dim x as Integer 행).

관련 문제