Dear friends,
I want to create a script that:
cuts cell B1 and pastes in A2
cuts cell B4 and pastes in A5
cuts cell B7 and pastes in A8
and so on and so forth.
First I tried:
tell application "Microsoft Excel"
activate object worksheet "Sheet1"
set cutcel to "B1"
set pastecel to "A2"
set repeatnum to 1
repeat with repeatnum from 1 to 5 (* change number when done *)
cut range range cutcel
paste worksheet active sheet destination range range pastecel
set cutcel to cutcel + 3 (*I want it to be B4, B7, B10, etc*)
set pastecel to pastecel + 3 (*I want it to be A5, A8, A11, etc*)
set repeatnum to repeatnum + 1
tell application "System Events" to set the clipboard to ""
end repeat
end tell
Of course this didn’t work, so I tried:
tell application "Microsoft Excel"
activate object worksheet "Sheet1"
set myrow1 to 1
set mycol1 to 2
set myrow2 to 2
set mycol2 to 1
set repeatnum to 1
repeat with repeatnum from 1 to 50 (* change number when done *)
set firstcel to (get address of cell mycol1 of row myrow1 of active sheet)
set lastcel to (get address of cell mycol2 of row myrow2 of active sheet)
cut range range firstcel
paste worksheet active sheet destination range range lastcel
set myrow1 to myrow1 + 3
set myrow2 to myrow2 + 3
set repeatnum to repeatnum + 1
tell application "System Events" to set the clipboard to ""
end repeat
end tell
A bonus would be to know how to use applescript to tell excel to insert a row (I don’t know why I can’t find this in the documentation…)
But this didn’t work either… what am I missing? And is there a much easier way to do this that I have overlooked?
(I’ve read all the applescript documentation but find it very overwhelming and can’t sort out what to do. As you can tell I’m not really a programmer!)
Thank you so much for any help in advance