Skip to main content

Count if Text is Bold in Google Sheet


Is there a way we can count or display the sum of bold text in the spreadsheet?


Solution:

Running a script in Google Apps Script.


Cons:

    - when the text is changed or updated the sum or count does not update

    - need to run the script every time when you edit the spreadsheet


function countboldcells() {
var book = SpreadsheetApp.getActiveSpreadsheet();
var sheet = book.getActiveSheet();
var range_input = sheet.getRange("A2:A18");
var range_output = sheet.getRange("A19");
var cell_styles = range_input.getFontWeights(); // getFontStyle can only return 'italic' or 'normal'
var count = 0;

for(var r = 0; r < cell_styles.length; r++) {
for(var c = 0; c < cell_styles[0].length; c++) { // isBold is a method for Google Documents only (not sheets)
if(cell_styles[r][c] === "bold") { // you need at least two '=' signs // also include the index of cell_styles
count = count + 1; // count += 1 would also work
}
}
}
range_output.setValue(count); // make sure you setValue only when booth loops are done.
}

Change the code (text in green) to the range of the text.

var range_input = sheet.getRange("A2:A18"); 

Change the code (text in green ) to the cell where the sum will be displayed.

var range_output = sheet.getRange("A19");

Comments

Popular posts from this blog

How To Remove Search Bar in Infinix Note 4

You might want to remove the Search Bar displayed in your Infinix Note 4 phone but you don't know how to. Here is the guide to remove or disable the Search Bar on your mobile phone. 1. Long Press on your home screen. 2. Press the "Menu Button" 3. Find and select the "Other Settings" 4. Turn off the settings for Search Bar (by swiping the button from right to left and it will turn from color green into gray color) And, if you wanted to display it again. Just follow the same procedure and turn on the setting for the Search Bar. If you wish to display it again just swipe the button from left to right (from the color gray will turn into green).

How to Translate Text in Google Sheets

 Updated post here: https://werkify.blogspot.com/2023/02/translate-text-in-google-sheets-using-the-googletranslate-formula.html Having a hard time to translate text in Google Sheets? Here is a tip on how you can do it. GOOGLETRANSLATE Function Syntax GOOGLETRANSLATE(text, [source_language, target_language])   - text ~ the cell (text) you want to translate      - source language ~ the original language of the text; if you don't know you can use "auto"      - target language ~ the language you want the text to be translated ( language code usually start with the first two letters e.g. English ~ "en" , Korean ~ "ko" ) Is your language supported? Browse the list of Google Translate Supported Language . Translate My Sheet Add-on Translate My Sheet This simple Google Add-on allows you to translate your spreadsheet in more of 100 languages! Two options are available:      - Translate your selected range  ...