i have column structure similar below one
author book ---- ---- ---- ---- vicky book1 vicky book2 giri book1 giri book3
the author
column in column b
, book
column might come in column based on other column datas
i want select values in these 2 columns
i tried
filearray = range("b4:b" & finalrow & "," & endcolumn).value
here first part working fine, finalrow
contains row number till record there, , endcolumn book details available
if use
filearray = range("b4:b" & finalrow )
it getting values, when try add 1 more column throwing error
also tried below 1 too
filearray = range("b4:b9,s4:s9").value
but not getting values of s4:s9
how can desired values?
you can this:
dim filearray dim finalrow long dim targetcol long sheets("sheetname") ' change actual sheet name finalrow = .range("b" & .rows.count).end(xlup).row ' assuming "book" column header , headers in 3rd row ' find correct column number targetcol = .range("b3").entirerow.find("book").column filearray = array(.range("b4:b" & finalrow), _ .range(.cells(2, targetcol), .cells(finalrow, targetcol))) end
to values:
debug.print filearray(0)(1) ' returns vicky debug.print filearray(1)(1) ' returns author1
so it's 1st parenthesis enclosed number column number, second row.