excel - "apllication -defined or object oriented error" is throwing while compling vb code. working between multiple workbooks -


this part of code.

at 1st if, error popop coming saying "application-defined or object oriented error".

for row_num = 2 3      'column numbers     col_num = 6 7          'check grey color         if workbooks(book_name).worksheets("parameterlifecycles").range(cells(row_num, col_num), cells(row_num, col_num)).interior.color = rgb(217, 217, 217)              'check if software name empty             if not isempty(workbooks(book_name).worksheets("parameterlifecycles").range("s" & row_num))                  soft_rd = workbooks(book_name).worksheets("parameterlifecycles").range("s" & row_num)              else                 soft_rd = workbooks(book_name).worksheets("parameterlifecycles").range("b" & row_num)              end if              'exit row once software name obtained             col_num = 16[enter image description here][1] 

in workbooks(book_name).worksheets("parameterlifecycles").range(cells(row_num, col_num), cells(row_num, col_num)) cells taken activesheet , not workbooks(book_name).worksheets("parameterlifecycles")

the error occurs because source of range differs source of cells.

use:

... workbooks(book_name).worksheets("parameterlifecycles")  if .range(.cells(row_num, col_num), .cells(row_num, col_num)).interior.color = rgb(217, 217, 217)  ... end ... 

please note dot before cells. sure cells taken same sheet range.


Comments