Just made the switch to the mac from a PC and am trying to take advantage of AS for some things that I could do rather easily with AutoHotKey on the PC, but I haven’t been able to figure this one out.
Here’s my pseudo-code…
tell Excel
get the active cell
copy the active cell and the cell to the right of it
go down one row
paste the copied cells
go down one row
paste the copied cells
go down one row
end tell
And added bonus would be the ability to tell the script how many times to loop through this action.
tell application "Microsoft Excel"
set countOfCopies to 3
set sourceRange to get resize active cell column size 2
set destinationRange to get resize (get offset sourceRange row offset 1) row size countOfCopies
set value of destinationRange to get value of sourceRange
end tell
more compact, with a slightly different result depending on whether any formulas are involved is
tell application "Microsoft Excel"
set countOfCopies to 3
set sourceRange to get resize active cell column size 2
fill down (get resize sourceRange row size countOfCopies)
end tell
Thanks so much! This works like a charm. How can I move the active cell down three rows after the fill down command?
tell application "Microsoft Excel"
set countOfCopies to 3
set sourceRange to get resize active cell column size 2
fill down (get resize sourceRange row size countOfCopies)
end tell
Thanks also for the links. As I mentioned, I’m just getting started and appreciate the resources.
tell application "Microsoft Excel"
set countOfCopies to 3
set startRange to range (get address active cell)
set lastRow to first row index of (get end (cell 1 of (row -1 of (cells of (get entire column of startRange)))) direction toward the top)
set fillrange to get resize startRange column size 2 row size countOfCopies
repeat while (first row index of cell 1 of row 1 of fillrange) ≤ (lastRow)
fill down fillrange
set fillrange to get offset fillrange row offset countOfCopies
end repeat
end tell
I’m a medical student and take my board exams on July 2nd. After that I get a month of vacation and will definitely be spending some of that time learning more AS. I’m glad I found this community.