AppleScript to modify a cell based on another one

hnt007

Board Regular
Joined
Dec 18, 2021
Messages
98
Office Version
  1. 365
Platform
  1. MacOS
Thank you for helping me out. I'm trying to change cell N that contains the subcategory of a music track if it finds the track title I'm looking for in column R. (the same track titles appear multiple timex across the sheet and I can't modify the Excel to do a pivot table, and I can't add a macro either)

Code:
-- Declare variables
property searchTrackTitle : ""
property newSubCategory : ""

-- Display input box to get search term
display dialog "Enter the track title that you want to search for:" default answer ""
set searchTrackTitle to text returned of result

-- Display input box to get new SubCategory
display dialog "Enter the new SubCategory that you want to use:" default answer ""
set newSubCategory to text returned of result

-- Open Excel and set variables
tell application "Microsoft Excel"
    activate
    set sh to active sheet
    set rng to range "R:R" of sh
end tell

-- Loop through each cell in the range
repeat with cell in rng
    -- Check if the cell value matches the track title
    if value of cell is searchTrackTitle then
        -- Update the SubCategory for the track title
        set (text of cell(("N") as text)) of sh to newSubCategory
    end if
end repeat
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top