Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Newbie question defining ranges

For i = 1 To 17
Set uRange = Sheet1.Range(Cells(1, i), Cells(19, i))
uRange.AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Sheet3.Cells(1, i), Unique:=True
Next i

Can someone explain why this code works if I write it as above, but if
I change the CopyToRange to Sheet3.Range(Cells(1,i)) I just get
errors?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Newbie question defining ranges

You're lucky that it works. And if Sheet1 isn't the activesheet, then it won't
work.

set uRange = sheet1.range(sheet1.cells(1,i), sheet1.cells(19,i))

or to save typing:
with sheet1
set urange = .range(.cells(1,i),.cells(19,i))
end with

or even:
set urange = sheet1.cells(1,i).resize(19,1)
(it's 19 rows by 1 column)

===========

If you did this
sheet3.range(sheet3.cells(1,i))

it's like typing:
sheet3.range(sheet3.cells(1,i).value)
(since you ony provided a single argument to cells().)

And I'm guessing that sheet3.cells(1,i) did not contain anything that looked
like an address. So it blows up.

ElPresidente wrote:

For i = 1 To 17
Set uRange = Sheet1.Range(Cells(1, i), Cells(19, i))
uRange.AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Sheet3.Cells(1, i), Unique:=True
Next i

Can someone explain why this code works if I write it as above, but if
I change the CopyToRange to Sheet3.Range(Cells(1,i)) I just get
errors?


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining Ranges Steve Excel Worksheet Functions 5 May 28th 05 07:41 AM
Automatically Defining Ranges Patrick Molloy[_2_] Excel Programming 0 May 5th 05 07:39 AM
Re-defining Ranges in VBA aehan Excel Programming 3 March 24th 05 05:15 PM
Defining ranges in VB code Rachael Moody Excel Programming 5 January 27th 04 02:21 PM
Defining Ranges Greg Ghavalas Excel Programming 2 July 9th 03 10:10 PM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"