excel - Class won't work -


i'm learning work classes in vba. i'm attempting write 1 gets true used range. code in class module looks this:

option explicit private mysheet range  public property cltrueusedrange() range     set cltrueusedrange = trueusedrange(mysheet) end property  public property let cltrueusedrange(byref wssource range)     mysheet = wssource end property private function trueusedrange(byref wssource worksheet) range dim rlastcell range  wssource     set rlastcell = .cells.find(what:="*", after:=.cells(1, 1), lookin:=xlformulas, lookat:= _             xlpart, searchorder:=xlbyrows, searchdirection:=xlprevious, matchcase:=false)     set trueusedrange = .range("$a$1:" & rlastcell.address) end  end function 

when try run it, error message, stating: byref type mismatch

what not correct in refrences in code?

your function expects sheet, not range. need: set cltrueusedrange = trueusedrange(mysheet.worksheet) or change code below, , pass worksheet when call it. also, property let needs property set assigning object:

option explicit private mysheet worksheet  public property cltrueusedrange() range     set cltrueusedrange = trueusedrange(mysheet) end property  public property set sheet(byref wssource worksheet)     set mysheet = wssource end property private function trueusedrange(byref wssource worksheet) range dim rlastcell range  wssource     set rlastcell = .cells.find(what:="*", after:=.cells(1, 1), lookin:=xlformulas, lookat:= _             xlpart, searchorder:=xlbyrows, searchdirection:=xlprevious, matchcase:=false)     set trueusedrange = .range("$a$1:" & rlastcell.address) end  end function 

and use: set rdata.sheet = activesheet


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -