Hello.
I have been monkeying around with some more scripting in Excel 2008 and have come up with some problems i can’t figure out.
In this first part I would like to find the used range of the document and autofill row numbers all the way to the final row. For now I put in a number manually and it does exactly what i’d like for it to do automatically.
tell application "Microsoft Excel"
activate
insert into range column "A:C" of worksheet 1 of active workbook shift shift to right
set value of cell ("A1") to 1
set value of cell ("A2") to 2
autofill range "A1:A2" destination range "A1:A3760"
sort range "D1" order1 sort ascending key1 column ¬
"D:D" header header no without match case
end tell
one thing that i would like to add to the above bit of code is for the script to move any dates from column D over to column B. If i could also “find” a text string (e.g. “Totals for vehicle nbr:”) in column D and move the appropriate cells over to column C that would be magical.
The next part also works, but errors out at the end with “Microsoft Excel got an error: The object you are trying to access does not exist”
the object is to start from the bottom and copy each subtotal’s label to its respective line items. The error pops up when the top of the document is reached. I’d like to be able to use the “used range” to tell it where to start and stop.
tell application "Microsoft Excel"
activate
set cell_No to 3760
set cell_dest to "not empty"
set cell_source to "not empty"
repeat until cell_No is "1"
set cell_source to value of cell ("C" & cell_No)
set cell_dest to value of cell ("C" & cell_No - 1)
if cell_dest is "" then
set value of cell ("C" & cell_No - 1) to cell_source
end if
set cell_No to cell_No - 1
end repeat
end tell
The next part is the same thing in reverse. It’s copying the dates down into the individual line items. The problem with this piece is that it doesn’t stop when it gets to the row i tried to tell it to stop at. As above i’d like to be able to use the “used range” to set the start and end points.
tell application "Microsoft Excel"
activate
set cell_No to 1
set cell_dest to "not empty"
set cell_source to "not empty"
repeat until cell_No is "3760"
set cell_source to value of cell ("B" & cell_No)
set cell_dest to value of cell ("B" & cell_No + 1)
if cell_dest is "" then
set value of cell ("B" & cell_No + 1) to cell_source
end if
set cell_No to cell_No + 1
end repeat
end tell
the final bit is just a question of whether the “sort” command at the beginning is necessary or not…
tell application "Microsoft Excel"
delete range column "A:A" shift shift to left
sort range "C1" order1 sort ascending key1 column "C:C" header header no without match case
try
delete range (entire row of (special cells of range "C:C" type cell type blanks)) shift shift up
end try
end tell
If i want to enter the variables manually it all works, but I’m sure someone knows a better way.
any help anybody can give would be very much appreciated.
-david