Skip to content

Instantly share code, notes, and snippets.

@metzenseifner
Created February 18, 2014 23:37
Show Gist options
  • Save metzenseifner/9082899 to your computer and use it in GitHub Desktop.
Save metzenseifner/9082899 to your computer and use it in GitHub Desktop.
Color Columns for Excel
tell application "Microsoft Excel"
set act_doc to active sheet
set sel_range to selection
set column_list to columns of sel_range
set sel_count to count of cells of sel_range
set the_Count to 1
set row_Count to count of rows of sel_range
set last_row to row_Count
repeat with i from 1 to sel_count
try
if the_Count is 1 then
set yellow to {255, 240, 168}
set color of interior object of item i of column_list to yellow
repeat with irow from 2 to (last_row)
if irow mod 2 = 0 then
set row_number to "even"
end if
if irow mod 2 ≠ 0 then
set row_number to "odd"
end if
if row_number is "even" then
set color of interior object of (row irow of item i of column_list) to {231, 215, 144}
end if
end repeat
else
if the_Count is 2 then
set blue to {124, 232, 247}
set color of interior object of item i of column_list to blue
repeat with irow from 2 to (last_row)
if irow mod 2 = 0 then
set row_number to "even"
end if
if irow mod 2 ≠ 0 then
set row_number to "odd"
end if
if row_number is "even" then
set color of interior object of (row irow of item i of column_list) to {127, 215, 232}
end if
end repeat
else
if the_Count is 3 then
set green to {139, 255, 184}
set color of interior object of item i of column_list to green
repeat with irow from 2 to (last_row)
if irow mod 2 = 0 then
set row_number to "even"
end if
if irow mod 2 ≠ 0 then
set row_number to "odd"
end if
if row_number is "even" then
set color of interior object of (row irow of item i of column_list) to {148, 234, 161}
end if
end repeat
else
if the_Count is 4 then
set pink to {255, 178, 193}
set color of interior object of item i of column_list to pink
repeat with irow from 2 to (last_row)
if irow mod 2 = 0 then
set row_number to "even"
end if
if irow mod 2 ≠ 0 then
set row_number to "odd"
end if
if row_number is "even" then
set color of interior object of (row irow of item i of column_list) to {227, 160, 175}
end if
end repeat
else
if the_Count is 5 then
set purple to {207, 181, 254}
set color of interior object of item i of column_list to purple
repeat with irow from 2 to (last_row)
if irow mod 2 = 0 then
set row_number to "even"
end if
if irow mod 2 ≠ 0 then
set row_number to "odd"
end if
if row_number is "even" then
set color of interior object of (row irow of item i of column_list) to {177, 162, 240}
end if
end repeat
end if
end if
end if
end if
end if
end try
if the_Count is less than 5 then
set the_Count to the_Count + 1
else
if the_Count is 5 then
set the_Count to 1
end if
end if
end repeat
get columns of sel_range
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment