|
-
Apr 27th, 2012, 12:27 AM
#1
Thread Starter
New Member
[RESOLVED] VBA referencing cell ranges in different sheets
syntax question this time, kind of a spinoff from my question about using a variable for countif
Code:
WorksheetFunction.Sum(Sheet21.Range("H1045:H1555"))
works
Code:
WorksheetFunction.Sum(Sheet21.Range(Cells(1045,8),Cells(1555,8)))
fails with a 400 error
but
Code:
Set vals = Range(Cells(firstrow, 11), Cells(rowindex - 1, 11))
this works. firstrow and rowindex are integer variables, vals is a range variable. by works i mean it sets the value fine, it isn't meant to do the same thing as the first two. noting this one b/c it lets me use cells(), whereas the other did not
so my question here is with regard to using the Cells() object to denote the cell references within a range. i assume the failed case has something to do with referencing a range from a different sheet. how can i correct this?
the reason i need to use cells() rather than "A1:B5" or something like that, is b/c i need a variable range, so i want toss a variable into Cells()
-
Apr 27th, 2012, 12:50 PM
#2
Junior Member
Re: VBA referencing cell ranges in different sheets
Try declaring before the cells which sheet you want to look at. For instance:
Code:
WorksheetFunction.Sum(Sheet21.Range(Sheet21.cells(1045,8),Sheet21.Cells(1555,8)))
Amend your other code the same way.
HTH
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|