excel - VBA Range Syntax Issue -
i'm trying create range use in concatinate function, i'm having unknown errors. have attached entire code, error appears during 'myrange' section. goal of code divide steps of process 360 minute shifts, , list of parts , tools required (found in column h). appreciated!
private sub commandbutton1_click()  dim duration integer, n long, integer, x integer, m integer dim myrange range  n = 3 m = 3 duration = 0 x = 0  = 1 50      duration = 0      while duration < 360          x = worksheets("sr060-sr070").cells(n, "f").value         duration = duration + x         n = n + 1      wend      myrange = range(worksheets("sr060-sr070").cells(m, "h"), worksheets("sr060-sr070").cells(n, "h"))     worksheets("shifts").cells(1, i).value = concatinateallcellvaluesinrange(myrange)     m = n  next  end sub  function concatinateallcellvaluesinrange(sourcerange excel.range) string       dim finalvalue string      dim cell excel.range      each cell in sourcerange.cells     finalvalue = finalvalue + cstr(cell.value)     next cell      concatinateallcellvaluesinrange = finalvalue end function      
this problemmatic:
myrange = range(worksheets("sr060-sr070").cells(m, "h"), _                 worksheets("sr060-sr070").cells(n, "h"))   the range() method here has no worksheet qualifier, default active worksheet, - if it's not "sr060-sr070" - raise error because cells() calls referencing different sheet.
this better as:
with worksheets("sr060-sr070")     set myrange = .range(.cells(m, "h"), .cells(n, "h")) end   (and adding set pointed out chipsletten)
Comments
Post a Comment