Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing Cells within Named Range in VBA

Tags:

excel

vba

I'd like to know if its possible to use Cells(r, c) within a named range in VBA. Ex.: I have named range "Test" to be A1:B5 and I am working on a Macro that loops through this range, however I'd like to avoid explicit declarations of ranges as much as possible, so sheet manipulation can be as easier as possible.

In case what I said wasnt possible, I basically need to be able to loop/write through cells in the named ranges, if there is another approach for this I'd be more than glad to get a suggestion.

Thanks!

like image 688
Matias Scardia Avatar asked Mar 19 '23 11:03

Matias Scardia


1 Answers

Sure, you can simply use e. g.

Worksheets("name").Range("Test").Cells(r, c)

and

Dim c As Range
For Each c In Worksheets("Name").Range("Test").Cells
    Debug.Print c.Address
Next
like image 75
KekuSemau Avatar answered Mar 28 '23 07:03

KekuSemau