#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Repeat

In another language I am familiar with if I wanted to express the text
"-----" I could say repeat("-",5). Is there something similar in VBA?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Repeat

Hi Mike

Try this:

Dim MyString
MyString = String(5, "*") ' Returns "*****".

"Mike H." wrote:

In another language I am familiar with if I wanted to express the text
"-----" I could say repeat("-",5). Is there something similar in VBA?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Repeat

On Dec 12, 12:45 pm, Mike H. wrote:
In another language I am familiar with if I wanted to express the text
"-----" I could say repeat("-",5). Is there something similar in VBA?


Hi
You could make your own

Public function repeat(inputstring as Variant, repetitions as Long) as
String
Dim temp as String, i as Long
Temp = Cstr(inputstring) 'incase number inputted
For i = 1 to repetitions
temp = temp & inputstring
Next i
repeat = temp
end function

you might need to test unusual inputs.

regards
Paul


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Repeat

Just a quick follow up... the String function will only repeat single
characters (which, of course, is what the OP seems to have asked for), but
if one wanted to repeat, say, the string value "AB" some number of times,
trying this...

MyString = String(5, "AB")

would result in "AAAAA" being assigned to the variable. The following is one
method to repeat the string "AB", say, five times...

MyString = Replace(String(5, Chr$(1)), Chr$(1), "AB")

Of course, you could replace the "AB" text string with any string of
characters.

Rick


"Trevor Williams" wrote in
message ...
Hi Mike

Try this:

Dim MyString
MyString = String(5, "*") ' Returns "*****".

"Mike H." wrote:

In another language I am familiar with if I wanted to express the text
"-----" I could say repeat("-",5). Is there something similar in VBA?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeat Cocoman Excel Discussion (Misc queries) 4 July 31st 09 08:50 AM
Repeat F2 briank Excel Programming 2 September 19th 05 06:19 PM
how to repeat rows at the bottom while using the rows repeat at to Rows to repeat at the bottom Setting up and Configuration of Excel 1 August 31st 05 02:06 PM
Title Cut Off if Rows to Repeat & Columns to Repeat are Both Selec unibaby Excel Discussion (Misc queries) 2 August 24th 05 04:29 PM
Repeat job Jw Excel Programming 10 February 16th 04 08:04 PM


All times are GMT +1. The time now is 06:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"