Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Using variable in CopyToRange:=

I have the following code to extract unique values from a column of data. I
need to replace the "O2" with a variable. Does this field only allow " " and
not variables?

BrianR

'extract unique IDs from column A
With Sheets(Sheet)
Range("A2:A" & last_row_used_local).AdvancedFilter
Action:=xlFilterCopy, _
CopyToRange:=.Range("O2"), Unique:=True

'sort the unique IDs
.Range(.Range(store_list_column),
..Range(store_list_column).End(xlDown)) _
.Sort Key1:=.Range("O2"), Order1:=xlAscending, Header:=xlYes
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 341
Default Using variable in CopyToRange:=

No, that should work fine.
Try this as a first step.
You will have to determine how you are going to set that range.

--
Allllen


"BrianR" wrote:

I have the following code to extract unique values from a column of data. I
need to replace the "O2" with a variable. Does this field only allow " " and
not variables?

BrianR


Dim myrange as range '****changed
Set myrange = range("O2") '****changed

'extract unique IDs from column A
With Sheets(Sheet)
Range("A2:A" & last_row_used_local).AdvancedFilter
Action:=xlFilterCopy, _
CopyToRange:=.Range(myrange), Unique:=True '****changed

'sort the unique IDs
.Range(.Range(store_list_column),
.Range(store_list_column).End(xlDown)) _
.Sort Key1:=.Range(myrange), Order1:=xlAscending, Header:=xlYes '****changed
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using variable in CopyToRange:=

Check your other thread.

BrianR wrote:

I have the following code to extract unique values from a column of data. I
need to replace the "O2" with a variable. Does this field only allow " " and
not variables?

BrianR

'extract unique IDs from column A
With Sheets(Sheet)
Range("A2:A" & last_row_used_local).AdvancedFilter
Action:=xlFilterCopy, _
CopyToRange:=.Range("O2"), Unique:=True

'sort the unique IDs
.Range(.Range(store_list_column),
.Range(store_list_column).End(xlDown)) _
.Sort Key1:=.Range("O2"), Order1:=xlAscending, Header:=xlYes
End With


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Using variable in CopyToRange:=

The "O" in my address is actually being passed in the subroutine as an
integer. I tried this but I'm getting a runtime 1004 error.

Set DestCell = Sheets(Sheet).Range(Cells(2, ID_List))

"Allllen" wrote:

No, that should work fine.
Try this as a first step.
You will have to determine how you are going to set that range.

--
Allllen


"BrianR" wrote:

I have the following code to extract unique values from a column of data. I
need to replace the "O2" with a variable. Does this field only allow " " and
not variables?

BrianR


Dim myrange as range '****changed
Set myrange = range("O2") '****changed

'extract unique IDs from column A
With Sheets(Sheet)
Range("A2:A" & last_row_used_local).AdvancedFilter
Action:=xlFilterCopy, _
CopyToRange:=.Range(myrange), Unique:=True '****changed

'sort the unique IDs
.Range(.Range(store_list_column),
.Range(store_list_column).End(xlDown)) _
.Sort Key1:=.Range(myrange), Order1:=xlAscending, Header:=xlYes '****changed
End With

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
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
Run-time Error'91: Object variable or With block variable not set DynamiteSkippy Excel Programming 4 September 26th 05 07:47 AM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 08:42 PM.

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

About Us

"It's about Microsoft Excel"