ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Spaces in VBA (https://www.excelbanter.com/excel-programming/338707-spaces-vba.html)

Otto Moehrbach

Spaces in VBA
 
Excel 2002, WinXP
Say that I have two cells, A1 & B1, with entries in each. I want to
concatenate those two values in, say C1. But I want a number of spaces
between them. That's easy to do if the number of spaces is fixed. But I
have a situation where the number of spaces is a variable, say NumSpaces.
How do I code the concatenation? Something like:
Range("C1").Value=[A1].Value & NumSpaces??? & [B1].Value
Thanks for your help. Otto



Norman Jones

Spaces in VBA
 
Hi Otto,

One way:

Sub Tester()
Dim NumSpaces As Long

NumSpaces = 10
Range("C1").Value = [A1].Value & _
Application.Rept(" ", NumSpaces) & [B1].Value
End Sub

---
Regards,
Norman



"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
Say that I have two cells, A1 & B1, with entries in each. I want to
concatenate those two values in, say C1. But I want a number of spaces
between them. That's easy to do if the number of spaces is fixed. But I
have a situation where the number of spaces is a variable, say NumSpaces.
How do I code the concatenation? Something like:
Range("C1").Value=[A1].Value & NumSpaces??? & [B1].Value
Thanks for your help. Otto




Ian

Spaces in VBA
 
One way is to have a string of spaces at least as long as you will ever
need, then select part of this.

spaces = " "
Range("C1").Value = Range("A1") & Left(spaces, Numspaces) & Range("B1")

I assume you get NumSpaces from elsewhere.

--
Ian
--
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
Say that I have two cells, A1 & B1, with entries in each. I want to
concatenate those two values in, say C1. But I want a number of spaces
between them. That's easy to do if the number of spaces is fixed. But I
have a situation where the number of spaces is a variable, say NumSpaces.
How do I code the concatenation? Something like:
Range("C1").Value=[A1].Value & NumSpaces??? & [B1].Value
Thanks for your help. Otto




Dave Peterson

Spaces in VBA
 
range("c1").value = range("a1").value & space(numspaces) & range("b1").value



Otto Moehrbach wrote:

Excel 2002, WinXP
Say that I have two cells, A1 & B1, with entries in each. I want to
concatenate those two values in, say C1. But I want a number of spaces
between them. That's easy to do if the number of spaces is fixed. But I
have a situation where the number of spaces is a variable, say NumSpaces.
How do I code the concatenation? Something like:
Range("C1").Value=[A1].Value & NumSpaces??? & [B1].Value
Thanks for your help. Otto


--

Dave Peterson

Otto Moehrbach

Spaces in VBA
 
Norman, Ian, Dave
Thanks for your help with this. Otto
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
Say that I have two cells, A1 & B1, with entries in each. I want to
concatenate those two values in, say C1. But I want a number of spaces
between them. That's easy to do if the number of spaces is fixed. But I
have a situation where the number of spaces is a variable, say NumSpaces.
How do I code the concatenation? Something like:
Range("C1").Value=[A1].Value & NumSpaces??? & [B1].Value
Thanks for your help. Otto





All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com