VBA/Excel Application-defined or object-defined error -
getting application-defined or object-defined error in excel vba macro , i'm not sure why. i'm guessing has how calling cell reference. i've looked @ of other similar questions this. similar, missing mistake is.
here's code:
set alliancesheet = worksheets(2) dim yearbeginrange range dim yearendrange range dim year integer dim beginrow long dim endrow long dim countryrange range 'dim ws worksheet 'dim wsname string year = 1965 'wsname = "ally-" & year set yearbeginrange = alliancesheet.range("c1", alliancesheet.range("c1").end(xldown)).find(what:=year, after:=alliancesheet.range("c1"), lookin:=xlformulas, _ lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, _ matchcase:=false, searchformat:=false) if yearbeginrange nothing msgbox year & "begin year not found" else 'msgbox year & "begin year found!" 'debug.print yearbeginrange.row 'debug.print typename(yearbeginrange.row) beginrow = yearbeginrange.row end if set yearendrange = alliancesheet.range("c1", alliancesheet.range("c1").end(xldown)).find(what:=year + 1, after:=alliancesheet.range("c1"), lookin:=xlformulas, _ lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, _ matchcase:=false, searchformat:=false) if yearbeginrange nothing msgbox year & "end year not found" else endrow = yearendrange.row end if set countryrange = alliancesheet.range(alliancesheet.cells(1, beginrow), alliancesheet.cells(1, endrow)) 'debug.print beginrow 'debug.print endrow 'debug.print wsname end sub
the error comes @ the:
set countryrange = alliancesheet.range(alliancesheet.cells(1, beginrow), alliancesheet.cells(1, endrow))
i know i'm missing basic in advance. fyi, beginrow= 65930 , endrow = 81430 in case.
you have arguments .cells
reversed - should row, column
, not column, row
:
set countryrange = alliancesheet.range(alliancesheet.cells(beginrow, 1), _ alliancesheet.cells(endrow, 1))
Comments
Post a Comment