Use REPT() to draw in-cell bar charts / sparklines

Use REPT() to draw in-cell bar charts / sparklines

The REPT() function is used to repeat a text, 'n' number of times. This can be used in interesting ways. For example, you can use this function to draw a bar chart within a cell.

Here is a sample spreadsheet which uses the REPT() function for in-cell charts. 



This spreadsheet holds the statistics of previous Wimbledon championship winners by Country. The range B3:B16 is named 'gentscount' and the range F3:F13 is named 'ladiescount'. Cell D2 is named 'maxbars' and it refers to the maximum width of the bar chart. You can view the various named ranges on the spreadsheet by clicking on the Name Box, which is available at the top towards the left of the Formula Bar.

Now let us look at the formula used in cell C3:

=REPT("|";B3/MAX(gentscount)*maxbars)

The first argument to the REPT() function denotes the text to be repeated. We use the pipe symbol or the vertical bar,  | , in this case to achieve a bar graph feel. 

The second argument denotes the number of times the text should be repeated. In this case, we divide each country's count [  B3   ] with the maximum value in the range 'gentscount' [  MAX(gentscount)   ] to denote each country's count on a scale of 0 to 1. We then multiply it by the maximum number of bars [ maxbars ] configured in the spreadsheet. So in any event, the maximum width of the bar will be in control as per the value in cell 'maxbars'.

Finally, we apply the 'Times New Roman' font for these cells since the letter spacing in this font is minimal. 

We then copy the formula in Cell C3 to the rest of the cells. Since this is a regular formula, as soon as you change the data in the cells, the in-cell chart is automatically redrawn. Go ahead, and give the above spreadsheet a try. Use the 'Click to Edit' button to interact with the spreadsheet.

Hope you find this useful. If you have any interesting uses of functions, share it with us.


      • Sticky Posts

      • Slicers are now available in Zoho Sheet—filter your data interactively

        At Zoho Sheet, we diligently track user requests and feedback. In line with this, based on extensive user requests, we've integrated Slicers to pivot tables and are delighted to announce its release. Slicers are interactive visual filters that have add,
      • Check out the new Checkbox in Zoho Sheet

        Checkbox, the simple GUI widget that lets you choose between two mutually exclusive options i.e Yes or No, is now in Zoho Sheet. Having made it across the web, Checkbox is familiar but is still elusive to most spreadsheet software. Special developer ribbons, macros and all other complexities to add a checkbox to a spreadsheet? Not in Zoho Sheet. How to add Checkbox to Zoho Sheet? Adding a Checkbox in Zoho Sheet is simple. Select a cell/range and choose "Checkbox" in "Input Controls" under the Format
      • Format and analyze spreadsheet data with Zoho Sheet's Table

        While a spreadsheet helps you compile data for easy analysis, formatting helps make your data more comprehensible. We are happy to announce the release of Table, a crucial tool for improving data formatting in Zoho Sheet. More than a formatting tool,
      • Introducing Data Bars: Graphically represent changes in data within the cells

        Conditional formatting has helped millions of spreadsheet users analyze and highlight their data more efficiently. In addition to the classic rules, color scales, and icon sets available in Zoho Sheet, you can now apply Data Bars, a convenient method
      • Zia in Zoho Sheet now makes suggestions on conditional formats, picklists, and checkboxes

        Zia, Zoho's popular AI assistant, has been helping users succeed across Zoho applications since inception. In Zoho Sheet, Zia helps users efficiently build reports and analyze data with recommendations about data cleaning, charts, and pivot table. Also,