Friday, November 22, 2024

applescript – Enhancing one column of desk based mostly off one other

A few factors…

  • You could work with each the cell references and the cell values
  • Numbers does not will let you delete a cell
  • You could specify the desk within the script, not merely the sheet

What this script does is cycles via every worth of the usedList and cycle via the masterList to see if there’s a match. Each lists are reversed so later entries are processed first however given you can’t delete cells, this may not produce any profit.

When it finds an identical cell within the masterList, it clears the worth after which strikes on to the subsequent entry within the usedList — so it assumes that there might be solely a single match for every usedList merchandise.

If you wish to put the usedList right into a second desk, you are able to do so by together with ‘desk 2’ in any references to the usedList. If the 2 are in separate tables, then it’d make it simpler to kind the ensuing masterList, and thus push the clean cells down beneath any with a remaining worth.

inform software "Numbers"
    inform entrance doc
        inform desk 1 of sheet 1
            
            set br to vary "B2:B10"
            set cbr to reverse of (get cells of br)
            set vbr to worth of cells of br
            
            set cr to vary "C2:C10"
            set ccr to reverse of (get cells of cr)
            set vcr to worth of cells of cr
            
            set bc to size of cbr -- what number of cells in grasp listing
            repeat with cCell in ccr -- every cell reference in C
                set ex to exists worth of cCell -- true/false
                if ex then -- has precise worth
                    repeat with vb from 1 to bc -- every cell in B
                        set bCell to merchandise vb of cbr -- cell reference
                        if worth of bCell is the same as worth of cCell then
                            clear bCell
                            exit repeat -- strikes on after match
                        finish if
                    finish repeat
                    
                finish if
            finish repeat
        finish inform
    finish inform
finish inform

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles