need some code help please

G

Gary Keramidas

in the following code, i get the name from another sheet. if it's blank, it
just gives me the name, but if there is another name that goes in the same
cell, i put a / between them

how would i put a chr(10) after every 2nd name, so only 2 fit on a line in
each cell.


If .Value = "" Then
.Value = Left(Fname, Len(Fname) - 4)
Else
.Value = .Value & "/" & Left(Fname, Len(Fname) - 4)
End If
 
B

Bob Phillips

If .Value = "" Then
.Value = Left(Fname, Len(Fname) - 4)
Else
c = Len(.Value) - Len(Replace(.Value, "\", ""))
If c Mod 2 = 1 Then
.Value = .Value & "/" vbNewline
Else
.Value = .Value & "/"
End If
.Value = .Value & Left(Fname, Len(Fname) - 4)
End If
--


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
G

Gary Keramidas

thanks bob, had to make a couple changes, but it seems to work fine.

i was using this, Len(.Value) - Len(Replace(.Value, "/", "")) = 1 , but you
can see i was not using the mod function.

anyway, what i changed was:

1. you had a typo, a backslash instead of a slash in the formula.

2. the vbnewline didn't have the & in front of it and gave me the little
square box in the cell, so i changed it to chr(10)

thanks again.
 
B

Bob Phillips

Sorry about that, in my testing I just cut code to test for the number of
slashes, then added the rest in the posting.

Glad you sorted it.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top