Re: Setting a range using a variable
Re: Setting a range using a variable
- Subject: Re: Setting a range using a variable
- From: Stan Cleveland <email@hidden>
- Date: Fri, 28 Mar 2008 16:15:07 -0700
- Thread-topic: Setting a range using a variable
On 3/28/08 2:35 PM, "Raymond P Reedy" wrote:
> I have the following snippet of code in a script...
>
> set rng to (range "C6:C330")
> repeat with i from 6 to 330
> sort range ("C & i : J" & i) of worksheet "Sheet3" key1
> (range "c & i" of worksheet "Sheet3") ¬
> order1 sort descending orientation sort columns
> end repeat
>
> At runtime the range is calculated as..
>
> "C & i : J6" and the sort fails.
>
> How do I get the range to calc as "C6 : J6"
I see three things that are keeping your code from working:
1. The first range inside the repeat loop is missing two quotation marks and
one ampersand. You need two strings and two instances of the variable "i":
("C" & i & ":J" & i)
But your code has just one string and one instance of "i":
("C & i : J" & i)
2. The second range inside the repeat loop has one quotation mark out of
place and needs parenthesis around it. You need one string and one instance
of "i":
("C" & i)
But your code has just one string:
"c & i".
3. Since you're working with rows, you should change the sort "orientation"
from "sort columns" to "sort rows". (Excel can't sort a column that's just
one cell tall.)
Also, while not a big deal, the variable rng is defined, but never used.
With the needed fixes, your code should look like this:
repeat with i from 6 to 330
sort range ("C" & i & ":J" & i) of worksheet "Sheet3" ¬
key1 (range ("C" & i) of worksheet "Sheet3") ¬
order1 sort descending orientation sort rows
end repeat
HTH,
Stan C.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden