Option Explicit
Sub RepeatString()
Dim Mystr As String, OutPutStr1 As String, OutPutStr2 As String, OutPutStr3 As String
Dim i As Long, v As Long
Mystr = " KB article XX "
i = 10
'Method 1 - Worksheet function REPT
OutPutStr1 = Application.WorksheetFunction.Rept(Mystr, i)
Debug.Print "REPT Function " & vbNewLine & OutPutStr1
'Method 2 - Space and Replace. Useful in VB if REPT isn't available
OutPutStr2 = Replace(Space(i), " ", Mystr)
Debug.Print "Space and Replace " & vbNewLine & OutPutStr2
'Method 3 - The ugly FOR loop
For v = 1 To i
OutPutStr3 = OutPutStr3 & Mystr
Next v
Debug.Print "The ugly FOR loop " & vbNewLine & OutPutStr3
End Sub
|