PDA

View Full Version : [SOLVED:] To enter one space after single digit



abraham30
12-11-2013, 03:03 PM
Hello Everyone!

I want one macro which add only one space next to single digit within parenthesis
e.g. (2 日)

As one space is available between 2 and 日, I want to add one more space i.e. output should be (2 日)

-->The macro should work on single digit only.
See attached sheet where the affected row with red color.

Advance thanks

ashleyuk1984
12-11-2013, 03:18 PM
Ok, so to clarify... How is the information originally...

A: (2日) - (no spaces) - to be converted via macro to (2 日) (one space)
B: (2 日) - (one space) - to be converted via macro to (2__日) (two spaces) ??

I don't think this forum likes two spaces in between characters, so I'm just checking before working on it.


I guess something like this would work. (This is based on "B:" above)


Sub AddOneMoreSpace()

x = 0


Do Until x = 10


Cells.Replace What:="(" & x & " ", Replacement:="(" & x & " ", LookAt:=xlPart, _
SearchOrder:=xlByRows


x = x + 1
Loop


End Sub

Code still works when you strip it all the way down too.


Sub AddOneMoreSpace()

x = 0


Do Until x = 10


Cells.Replace What:="(" & x & " ", Replacement:="(" & x & " "


x = x + 1
Loop


End Sub

Bob Phillips
12-12-2013, 02:03 AM
Ashley, I would suggest you include that odd character in your search string as well, in case there is already two spaces.

snb
12-12-2013, 02:13 AM
Sub M_snb()
For j = 0 To 9
Columns(2).Replace Format(j, "(0 "), Format(j, "(0 ")
Next
End Sub

abraham30
12-12-2013, 03:04 AM
Thanks Ashley. its working fine.

The macro provided by SNB is not working. I have no idea. Any how the issue is resolved.
Thanks everyone for your support

snb
12-12-2013, 03:14 AM
I assumed the data residing in Column B

If they can be anywhere:


Sub M_snb()
For j = 0 To 9
Cells.Replace Format(j, "(0 "), Format(j, "(0 ")
Next
End Sub

ashleyuk1984
12-12-2013, 06:05 AM
Ashley, I would suggest you include that odd character in your search string as well, in case there is already two spaces.Hi xld that's a really good shout!! I tried to change my code, but I couldn't copy the strange character into the VBA screen - it would only give me a question mark... I guess you would have to declare it as some sort of CHR number ?? No idea what it is though. :(