Applescript Excel simple commands help

N

Newby

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

Hi - apologies for the simplicity/timewasting nature of this post:

I am new to Applescript and want to use it to do some simple things such as find text in a row and then delete the row. Can you offer some examples of script that can do this. I can find the text using something like:

find (range "1:1000" of worksheet "Sheet1") what "Concentration"

but then what do I use to select the row and delete it?

Thanks for any help!

Paul.
 
L

Laroche J

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

Hi - apologies for the simplicity/timewasting nature of this post:

I am new to Applescript and want to use it to do some simple things such as
find text in a row and then delete the row. Can you offer some examples of
script that can do this. I can find the text using something like:

find (range "1:1000" of worksheet "Sheet1") what "Concentration"

but then what do I use to select the row and delete it?

Thanks for any help!

Paul.

The result of Find is a range. Assign it to a variable, then use that
variable to set the deletion of the row. You must be careful though to check
if there are still cells to be found with the requested data; to this end
you must use "try" to prevent any runtime error. The beauty of it is that
AppleScript jumps out of the "try" loop when an error occurs, so you can use
it to your advantage to follow error-causing sentences with appropriate
code. See below for the example.

JL
Mac OS X 10.4.11
Office v.X 10.1.9



tell application "Microsoft Excel"

Activate

set FoundResult to false
try
set FoundCell to (Find every Cell What ¬
"Concentration" without MatchCase)
set FoundResult to true
Delete EntireRow of FoundCell
end try

repeat while FoundResult is true
set FoundResult to false
try
set FoundCell to FindNext every Cell after ActiveCell
set FoundResult to true
Delete EntireRow of FoundCell
end try
end repeat

end tell
 
N

Newby

Thanks for the help JL!

I've modified the script a little because a few of the commands that you used weren't recognized by my version of Excel 2008 for Mac (12.1.7) running on OSX 10.5.7 and I'm not too worried about runtime errors so it's ended up looking as below. Cheers, Paul.

tell application "Microsoft Excel"

activate
select range "A1"

set FoundResult to false

try
set FoundCell to (find range "1:1000" what "Concentration")
set FoundResult to true
delete entire row of FoundCell
end try

set i to 1
repeat while i ≤ 1000
set FoundResult to false


set FoundCell to (find range "1:1000" what "Concentration")
set FoundResult to true
delete entire row of FoundCell

set i to i + 1
end repeat

end tell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top