Hi Guys,
I am trying to run a loop through a range ex C4:c15 where it is populated with characters.
I would like to create a loop that populates each text by adding 6 extra spaces at the end.
Thanks for your replies in advance!
Adding spaces to excel using VBA
Page 1 of 15 Replies - 423 Views - Last Post: 17 August 2012 - 08:14 AM
Replies To: Adding spaces to excel using VBA
#2
Re: Adding spaces to excel using VBA
Posted 17 August 2012 - 07:17 AM
Please post the code of what you have tried so far using the [Code ] tags.
#3
Re: Adding spaces to excel using VBA
Posted 17 August 2012 - 07:32 AM
Dim rng As Range
rng = Worksheets("Sheet1").Range("C4:C15")
Dim val As String
Dim cell As Range
For Each cell In rng
val = cell.Value
val = val & " "
cell.Value = val
Next cell
End Sub
rng = Worksheets("Sheet1").Range("C4:C15")
Dim val As String
Dim cell As Range
For Each cell In rng
val = cell.Value
val = val & " "
cell.Value = val
Next cell
End Sub
#4
Re: Adding spaces to excel using VBA
Posted 17 August 2012 - 08:11 AM
I'm not that familiar with VBA, so can you tell me what it isn't doing?
I can see you're trying to loop around the range and add a space to the cell value and update it again.
So what does it actually do? What do you get written back to your cells?
Are the cells formatted so that you can display them as strings (extra spaces).
I can see you're trying to loop around the range and add a space to the cell value and update it again.
So what does it actually do? What do you get written back to your cells?
Are the cells formatted so that you can display them as strings (extra spaces).
This post has been edited by maj3091: 17 August 2012 - 08:12 AM
#5
Re: Adding spaces to excel using VBA
Posted 17 August 2012 - 08:13 AM
Hey DIC!
I just figured it out!
i had to write "set" before RNG..so
set rng = Worksheets("Sheet1").Range("C4:C15")
This will add 6 additional spaces to the cells.
Thanks very much!
I just figured it out!
i had to write "set" before RNG..so
set rng = Worksheets("Sheet1").Range("C4:C15")
This will add 6 additional spaces to the cells.
Thanks very much!
#6
Re: Adding spaces to excel using VBA
Posted 17 August 2012 - 08:14 AM
Glad you sorted it out and thanks for posting your solution for others.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|