vba - Object variable not set error? -
i'm c++/c# programmer , unfamiliar vba, i'm not problem code. it's throwing following error:
"run-time error '91': object variable or block variable not set."
that error being thrown on line in loop. right side of statement seems throwing error. problem line, , how go fixing it?
here's code snippet:
option explicit private gemployees() employee const glastnamestartingcell = "a4" const gnamescountcell = "a1" const gnamestab = "namestab" function buildemployeenamearray() ' declare variables dim inamecount integer dim wksactive object ' counter dim integer ' select sheet names set wksactive = sheets(gnamestab) ' number of names on sheet inamecount = wksactive.range(gnamescountcell) ' resize array appropriate redim gemployees(0 inamecount - 1) ' fill out employee list = 0 inamecount - 1 gemployees(i).mlastname = wksactive.range(glastnamestartingcell).offset(i, 0).value next end function
employee class module. here's relevant information file.
option explicit public mlastname string private sub class_initialize() ' initialize variables mlastname = "" end sub
you missing creation of actual employee add array.
dim e employee ' fill out employee list = 0 inamecount - 1 'create new employee each time through loop set e = new employee gemployees(i)=e 'set last name appropriately gemployees(i).mlastname = wksactive.range(glastnamestartingcell).offset(i, 0).value next
this fix problem.
the array never sets type, either, way doing this, i'm not sure how have gotten similar syntax work in c++/c#.
Comments
Post a Comment