Skip to content

Instantly share code, notes, and snippets.

@Narvey
Last active June 29, 2017 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narvey/8d4c6239725c094059d106b75e6a23d0 to your computer and use it in GitHub Desktop.
Save Narvey/8d4c6239725c094059d106b75e6a23d0 to your computer and use it in GitHub Desktop.
Deletes lines that have certain text in cell B - Shared with Script Lab
name: Delete certain lines
description: Deletes empty lines and lines that have certain text in cell B representing a row that is not in use
author: Narvey
host: EXCEL
api_set: {}
script:
content: "$(\"#run\").click(run);\r\n\r\nasync function run()\r\n{\r\n try\r\n {\r\n await Excel.run(async (ctx) =>\r\n {\r\n var deleteVal = document.getElementById(\"delete\").value.toLocaleLowerCase()\r\n var rows = ctx.workbook.worksheets.getActiveWorksheet().getUsedRange().load(\"values\")\r\n await ctx.sync()\r\n var rowNum = 0, used = 0, v = \"\"\r\n for (rowNum = rows.values.length-1; rowNum >= 0; rowNum--)\r\n {\r\n v = rows.values[rowNum][1]\r\n if (v == null || v.length == 0 || v.toLocaleLowerCase() == deleteVal)\r\n {\r\n rows.getRow(rowNum).delete(\"Up\")\r\n await ctx.sync()\r\n }\r\n }\r\n await ctx.sync()\r\n })\r\n }\r\n catch (error)\r\n {\r\n OfficeHelpers.UI.notify(error)\r\n OfficeHelpers.Utilities.log(error)\r\n }\r\n}\r\n"
language: typescript
template:
content: "<br><br><!--spacing for message boxes-->\r\n<button id=\"run\" class=\"ms-Button\">\r\n <span class=\"ms-Button-label\">Run</span>\r\n</button>\r\n<br>\r\n<label>Text to consider empty row:</label>\r\n<input type=\"text\" id=\"delete\" class=\"ms-Text\" value=\"Not in use\" />\r\n<br>\r\n\r\n"
language: html
style:
content: "/* Your style goes here */\r\n"
language: css
libraries: |
# Office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
# CSS Libraries
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
# NPM libraries
core-js@2.4.1/client/core.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
jquery@3.1.1
# IntelliSense: @types/library or node_modules paths or URL to d.ts files
@types/office-js
@types/core-js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment