REPT

Text Functions
(4.5/5)

Repeats text a specified number of times. Essential for creating visual bars, formatting text, and generating repeated patterns in Excel.

Interactive Formula Tester

=REPT("Hello, 3")

Complete Theory & Understanding

Master the fundamentals of Excel REPT function

Core Concept

The REPT function repeats a text string a specified number of times, creating concatenated repetitions. It's essential for creating visual bar charts, formatting displays, generating repeated patterns, and building simple text-based graphics in Excel.

Why Use REPT?

  • Create simple bar charts with characters
  • Format text with repeated separators
  • Create star rating displays
  • Show progress with repeated characters

Key Characteristics

Text Repetition

Repeats text string multiple times

REPT("Hello", 3) = "HelloHelloHello"

Visual Charts

Creates visual bars with characters

REPT("|", 10) creates bar chart

Dynamic Repetition

Number of times can be calculated

REPT("-", A1) repeats based on cell

Zero Repetitions

Returns empty string when number_times is 0

REPT("A", 0) = ""

Function Anatomy

=REPT(parameters...)
Required
Parameters:

Function-specific parameters

Returns
Return Value:

Function-specific return type

Primary Use Cases

Visual Bar Charts

Create simple bar charts with characters

Text Formatting

Format text with repeated separators

Star Ratings

Create star rating displays

Progress Indicators

Show progress with repeated characters

Theory Summary

Precise

Exact matching required

Position-Based

Returns numeric position

Error-Safe

Handles missing text gracefully

Syntax & Parameters

=REPT(text, number_times)
Required
text:

The text string to repeat

Required
number_times:

The number of times to repeat the text (must be >= 0)

Returns
Return Value:

Text string repeated the specified number of times

Description: Repeats text a specified number of times. Useful for creating visual bars and patterns.

Interactive Examples

Basic Repetition

Repeat text multiple times

"Hello, 3 times"
=REPT("Hello", 3)
HelloHelloHello

Repeats 'Hello' three times consecutively

VBA Implementation & Automation

Basic REPT in VBA

Simple VBA implementation of REPT function

' Basic REPT in VBA
Range("B1").Value = Application.WorksheetFunction.Rept("Hello", 3)
' Returns: "HelloHelloHello"

' Using VBA Rept function
Dim text As String
text = "-"
Dim repeatCount As Integer
repeatCount = 10
Range("B2").Value = Application.WorksheetFunction.Rept(text, repeatCount)
' Returns: "----------"

' Create visual bars for range
Sub CreateVisualBars()
    Dim cell As Range
    For Each cell In Range("A1:A10")
        If IsNumeric(cell.Value) Then
            Dim barLength As Integer
            barLength = Int(cell.Value)
            cell.Offset(0, 1).Value = Application.WorksheetFunction.Rept("|", barLength)
        End If
    Next cell
End Sub

' Create star rating
Sub CreateStarRating()
    Dim rating As Integer
    rating = 4
    Range("B1").Value = Application.WorksheetFunction.Rept("*", rating)
    ' Returns: "****"
End Sub

Advanced Visual Charts

Create dynamic visual charts and progress bars

' Create progress bar
Function CreateProgressBar(value As Double, maxValue As Double, barLength As Integer) As String
    Dim filledLength As Integer
    filledLength = Int((value / maxValue) * barLength)
    Dim emptyLength As Integer
    emptyLength = barLength - filledLength
    CreateProgressBar = Application.WorksheetFunction.Rept("█", filledLength) & _
                        Application.WorksheetFunction.Rept("░", emptyLength)
End Function

' Create horizontal bar chart
Sub CreateBarChart()
    Dim cell As Range
    Dim maxValue As Double
    maxValue = Application.WorksheetFunction.Max(Range("A1:A10"))
    
    For Each cell In Range("A1:A10")
        If IsNumeric(cell.Value) Then
            Dim barLength As Integer
            barLength = Int((cell.Value / maxValue) * 20)
            cell.Offset(0, 1).Value = Application.WorksheetFunction.Rept("=", barLength)
        End If
    Next cell
End Sub

' Format with separator
Sub FormatWithSeparator()
    Dim values() As Variant
    values = Array("A", "B", "C")
    Dim result As String
    Dim i As Integer
    result = values(0)
    For i = 1 To UBound(values)
        result = result & Application.WorksheetFunction.Rept("-", 3) & values(i)
    Next i
    Range("A1").Value = result
    ' Returns: "A---B---C"
End Sub

Business Applications

Visual Bar Charts

Create simple bar charts with characters

=REPT("|", A1)

Star Ratings

Create star rating displays

=REPT("*", B1)

Progress Indicators

Show progress with repeated characters

=REPT("=", A1*10)

Text Separators

Create separators in text

="Text" & REPT("-", 5) & "Text"

Common Issues & Solutions

Negative Number

REPT with negative number_times returns #VALUE! error

=REPT(A1, MAX(0, B1))

Solution: Ensure number_times is >= 0. Use MAX to prevent negatives: =REPT(text, MAX(0, number_times))

Decimal Number

REPT truncates decimal number_times

=REPT(A1, INT(B1))

Solution: This is expected. REPT uses integer part only. REPT("A", 2.7) = REPT("A", 2)

Very Large Numbers

REPT may be slow or cause issues with very large repetition counts

=REPT(A1, MIN(B1, 100))

Solution: Limit repetition count to reasonable values (typically < 32767). Consider alternative approaches for very large counts.

Empty Text

REPT with empty text returns empty string regardless of count

=REPT("", 10) returns ""

Solution: This is expected. Ensure text parameter contains at least one character.

Performance Tips & Best Practices

⚡ Performance Optimization

  • Use REPT efficiently with reasonable repetition counts
  • Avoid very large repetition counts (>10000)
  • Consider cell formatting for visual charts in some cases
  • Cache REPT results when used multiple times

🎯 Best Practices

  • Use REPT for visual bars and simple charts
  • Keep repetition counts reasonable for performance
  • Use single characters (|, =, *) for visual effects
  • Document REPT usage for visual formatting

💡 Pro Tips

  • REPT("|", value) creates simple bar charts
  • REPT("*", rating) creates star ratings
  • Combine with other text functions for complex patterns
  • Use REPT(CHAR(124), count) for vertical bars (|)