![]() |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 03:38 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com