Re: If statements in Excel
Re: If statements in Excel
- Subject: Re: If statements in Excel
- From: Stan Cleveland <email@hidden>
- Date: Tue, 04 Dec 2007 12:41:55 -0800
- Thread-topic: If statements in Excel
On 11/30/07 12:57 PM, Justin Laden wrote:
> Well, I appreciate your help, Stan and Paul, but I'm still having trouble.
>
> I have given up--for the moment--on trying to walk through an Excel
> column, parse each cell, then use if statements to alter the data of
> another cell in another column.
>
> Earlier, I think Stan suggested that I tackle my problem through Lists
> instead of Excel columns.
>
> I can take care of writing a list back into an Excel column, but the
> difficulty for me is walking through the list, and based on each item,
> performing an action--here with an if statement--truncating part of a
> string in an item, and then setting the truncated part of the string
> as the corresponding item in another list. The second (to be
> populated list) is empty originally, but based on the control
> statements in the first list, I want it to be populated with a string,
> or no data (maybe empty strings...).
>
> I'll worry about my truncation handler or method later.
>
> I've tried but no luck with the walk though, and control statement
> challenge of working with lists--here is what I came up with:
>
>
> (*repeat with i from 1 to (numItems)
> if item i of pageSizeRange = "1" then
> set item i of priceRange to "true"
> end if
> end repeat*)
>
> I greatly appreciate all your help so far!
>From an earlier post:
tell application "Microsoft Excel"
set rangeData to value of range "A1:C3"
--> {{375.0, 375.0, ""}, {326.45, 307.88, ""}, {48.55, 67.12, ""}}
end tell
Note that, in this case, the variable rangeData is set to a list of three
lists, each of which contains three items. The complete list represents all
data in the specified range (A1:C3). The items of the list (each a list
itself) represent the rows of the specified range. The items of each
sub-list represent the cells of that row.
Based on these facts, here's some code that may help (obviously, you'll need
to adjust somewhat to your specific situation):
set sourceQueNumCol to 1
set targetQueNumCol to 2
set paperSizeCol to 3
set paperStringCol to 4
-- grab data from Excel
tell application "Microsoft Excel"
set rangeData to formula of range "A1:D5"
end tell
-- cycle through rows of data
set numRows to count rangeData --> 5
repeat with thisRow from 1 to numRows
set rowData to item thisRow of rangeData
-- handle que number
set queNum to item sourceQueNumCol of rowData
if queNum is not "" then
set item targetQueNumCol of rowData to queNum
end if
-- handle page size
set pageSize to item paperSizeCol of rowData
if pageSize is "8.5x11" then
set item paperStringCol of rowData to "Letter"
else if pageSize is "11x17" then
set item paperStringCol of rowData to "Tabloid"
else
set item paperStringCol of rowData to ""
end if
end repeat
-- store data back to Excel
tell application "Microsoft Excel"
set rangeData to value of range "A1:D5"
end tell
I hope this demonstrates the concept and clarifies things a bit.
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