Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Repeat Character in VBA

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Repeat Character in VBA

There is a function called space that you could use

dim str as string
str = "this" & space(10) & "that"
--
HTH...

Jim Thomlinson


"Brad" wrote:

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Repeat Character in VBA

Just to add to Jim's reply...

There's another function that can be used with other non-space characters:

dim str as string
str = String(12, "x")

(It can also be used with space characters <bg.)



Jim Thomlinson wrote:

There is a function called space that you could use

dim str as string
str = "this" & space(10) & "that"
--
HTH...

Jim Thomlinson

"Brad" wrote:

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Repeat Character in VBA

Yeah but I loved the ironly that Brad had the function correct and that the
only error was *x instead of (x).
--
HTH...

Jim Thomlinson


"Dave Peterson" wrote:

Just to add to Jim's reply...

There's another function that can be used with other non-space characters:

dim str as string
str = String(12, "x")

(It can also be used with space characters <bg.)



Jim Thomlinson wrote:

There is a function called space that you could use

dim str as string
str = "this" & space(10) & "that"
--
HTH...

Jim Thomlinson

"Brad" wrote:

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Repeat Character in VBA

And just to add onto Dave reply, the String function only repeats single
characters; however, if you wanted to repeat multiple characters, all you
would have to do is couple the String or Space function with the Replace
function. For example, to produce a text string of, say, 100 "XO" character
pairs in a row, just do this...

HundredXOs = Replace(Space(100), " ", "XO")

or this would work also...

HundredXOs = Replace(String(100, "Z"), "Z", "XO")

where you can use any character you want to in place of the "Z".

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Just to add to Jim's reply...

There's another function that can be used with other non-space characters:

dim str as string
str = String(12, "x")

(It can also be used with space characters <bg.)



Jim Thomlinson wrote:

There is a function called space that you could use

dim str as string
str = "this" & space(10) & "that"
--
HTH...

Jim Thomlinson

"Brad" wrote:

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad


--

Dave Peterson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Repeat Character in VBA

Hi,

this adds 10 spaces to the end without a loop and with the use of
left/mid/right you could put the spaces anywhere

x = 10
mystring = "Mike H"
mystring = mystring + WorksheetFunction.Rept(" ", x)

Mike

"Brad" wrote:

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Repeat Character in VBA

Thanks to all for your posts!!

It is quite ironic that I was so close but yet had no idea.

Hope everyone has a great day today,

Brad

"Brad" wrote:

Thanks for taking the time to read my question

I would like add a space to my string x times, where x = an integer.

How can I do that with out using a loop statement?

x=10
eg: "there are 10 spaces between here" & space * x & "here."

Thanks,

Brad

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 a macro until the last line is empty or repeat it 1400 time marita Excel Programming 3 July 18th 08 01:40 PM
Repeat keystrokes to delete character in column Graeme at Raptup Excel Worksheet Functions 5 October 4th 07 05:57 PM
How do I repeat a character in a cell in Excel as / did in Lotus? SoSoPro Excel Discussion (Misc queries) 2 March 31st 07 04:29 AM
importing undelimited text file data, character-by-character The Mos$ Excel Programming 4 December 26th 05 11:01 AM
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


All times are GMT +1. The time now is 08:16 AM.

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"