excel VBA using Range() and ActiveCell.Offset() -
i'm using excel vba , i'm trying increment range selection in loop.
sub sorter() dim integer dim copyloc string = "e1" = 0 5 range(copyloc).select '//what type range() supposed take? selection.copy copyloc = activecell.offset(0, 6) '//what type activecell.offset return? next end sub
i'm sure problem data type activecell.offset returning. can tell me should use instead? kindly!
expanding on comment above. "range" object type. want dim variable "range" not string:
sub sorter() dim integer dim copyloc range set copyloc = range("e1") = 0 5 'copy copyloc , stick in cell offset 6 columns right copyloc.copy destination:=copyloc.offset(0,6) 'increment next row? set copyloc = copyloc.offset(1) next end sub
i'm guessing here @ trying accomplish, either way think in ballpark. if incrementing through 6 rows starting @ e1 use like:
sub sorter() dim rngrow range dim copyrange range set copyrange = range("e1:e6") 'loop through each row in range's "rows" collection each rngrow in copyrange.rows 'copy value "e" column "k" column in row rngrow.cells(1,11).value = rngrow.cells(1,5).value next rngrow end sub
being able loop/iterate through each item in collection, , understanding objects in vba part of collection hugely powerful.
for instance, looping through of sheets in thisworkbook.worksheets collection:
dim ws worksheet each ws in thisworkbook.sheets 'print name of worksheet "immediate" pane debug.print ws.name next ws
or looping through cells in range's "cells" collection:
dim rngcell range each rngcell in range("a1:c50").cells 'do cell next rngcell
Comments
Post a Comment