google spreadsheets. google script app. with cell location get it formating (font,…
- User
google spreadsheets. google script app. with cell location get it formating (font, align, etc.) and apply to another cell (range of cells)
- Assistant
To achieve this in Google Sheets using Google Apps Script, you can use the following script:
function copyFormatting() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sourceSheet = ss.getActiveSheet(); var targetSheet = ss.getSheetByName("Sheet2"); // Change "Sheet2" to the name of your target sheet var sourceRange = sourceSheet.getRange("A1"); // Change "A1" to the cell location from where you want to get the formatting var targetRange = targetSheet.getRange("A1:A10"); // Change "A1:A10" to the range of cells you want to apply the formatting to var sourceFontColor = sourceRange.getFontColor(); var sourceBackgroundColor = sourceRange.getBackground(); var sourceFontSize = sourceRange.getFontSize(); var sourceFontWeight = sourceRange.getFontWeight(); var sourceFontStyle = sourceRange.getFontStyle(); var sourceFontLine = sourceRange.getFontLine(); var sourceHorizontalAlignment = sourceRange.getHorizontalAlignment(); targetRange.setFontColor(sourceFontColor) .setBackground(sourceBackgroundColor) .setFontSize(sourceFontSize) .setFontWeight(sourceFontWeight) .setFontStyle(sourceFontStyle) .setFontLine(sourceFontLine) .setHorizontalAlignment(sourceHorizontalAlignment); } - User
=INDEX(Q3:Q20; MATCH(FALSE; TRIM(Q3:Q20)=""; 0)) but i want it to return not value of cell but its location (Q14 for example)
- Assistant
To modify the formula to return the location of the cell instead of the value in Google Sheets, you can use the CELL function within the INDEX and MATCH formula. Here's how you can do it:
- First, use the INDEX and MATCH function to find the first non-empty cell in the range Q3:Q20:
=MATCH(FALSE, TRIM(Q3:Q20)=""; 0)- Once you have the row number of the first non-empty cell, use the CELL function to get the location of that cell in a specific format (e.g., "Q14"):
=SUBSTITUTE(ADDRESS(MATCH(FALSE, TRIM(Q3:Q20)=""; 0) + ROW(Q3)-1, COLUMN(Q3), 4), "$", "")In the formula above, SUBSTITUTE is used to remove the dollar signs ($) from the cell reference. Here's a breakdown of the formula:
- MATCH(FALSE, TRIM(Q3:Q20)=""; 0) - Finds the row number of the first non-empty cell in the range Q3:Q20.
- ADDRESS(MATCH(FALSE, TRIM(Q3:Q20)=""; 0) + ROW(Q3)-1, COLUMN(Q3), 4) - Converts the row and column numbers into a cell address (e.g., 14).