Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ian Ian is offline
external usenet poster
 
Posts: 238
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default 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



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
how do I remove leading spaces and leave the remianing spaces w Debi Excel Worksheet Functions 6 February 28th 07 03:29 PM
spaces not recognized as spaces windsurferLA Excel Worksheet Functions 9 July 27th 06 11:49 AM
ADD SPACES Ronbo Excel Programming 13 March 16th 05 04:21 AM
A better way to get rid of spaces The parawon Excel Programming 4 February 14th 05 11:57 PM
Help copying a range with spaces to a range without spaces Andy Excel Programming 1 September 23rd 03 04:26 PM


All times are GMT +1. The time now is 02:03 PM.

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

About Us

"It's about Microsoft Excel"