excel - VBA: Array of Range References -
in vba, trying create array of range references. here's current attempt:
dim columnname() string dim colindex() long dim colrange() range colcount = 10 redim columnname(colcount) redim colindex(colcount) redim colrange(1 colcount) columnname(id) = "id" 'etc = 1 ubound(columnname) colindex(i) = ws.range("a1", "zz1").find(columnname(i), lookin:=xlvalues, matchcase:=false).column colrange(i) = ws.range(cells(2, colindex(i)), cells(lastrowindex, colindex(i))) if 1 = 1 'debugging application.screenupdating = true debug.print colrange(i).value debug.print colrange(i).address colrange(i).select application.screenupdating = false end if when try store multiple references in array, this:
i = 1 colindex(i) = 8 cells(2, colindex(i)) = 123 cells(lastrowindex, colindex(i)) =789 colrange(i) = nothing i have tried making colrange variant, nothing seems work. no solutions found via google or stackoverflow seemed address this.
further comment above, here example
sub sample() dim columnname() string dim rng range colcount = 10 redim columnname(colcount) id = 1 columnname(id) = "a" 'msgbox cells(1, columnname(1)).address cells(1, columnname(1)).value = "blah blah" set rng = cells(1, columnname(1)) rng msgbox .address .value = "something" '~~> whatever want range here end end sub avoid use of .select. directly perform action on range have done above. interesting read
Comments
Post a Comment