adding strings

  • Thread starter julian brotherton
  • Start date
J

julian brotherton

sub add_strings()
A = "4="
B = CELLS(ROW,"B") 'THE CONTENT OF THE CELLS IS 2
C= A + STR$(B)

END SUB

The result is 4= 2

I don't want the space between the 4= & the 2
Is there a way of combining the two, but removing the
leading space ??
 
B

Bob Phillips

Julian,

Try

Sub add_strings()
A = "4="
B = Cells(1, "B") 'THE CONTENT OF THE CELLS IS 2
C = A + Trim(Str$(B))

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
J

JULIAN BROTHERTON

Thanks. Worked fine.
Why doesn't the help file point to this simple function ??

Julian B
 
T

Tom Ogilvy

Actually, you don't need str$. If the cell actually contains a number
(which is why you would use str$ and help does say that str$ puts a space in
for the sign), you wouldn't need trim.

Both Trim and Str/str$ are documented in Excel VBA help.

Sub add_strings()
A = "4="
B = Cells(1, "B") 'THE CONTENT OF THE CELLS IS 2
C = A & B
End Sub

Sub add_strings()
A = "4="
B = Cells(1, "B") 'THE CONTENT OF THE CELLS IS 2
C = A & cStr(B)

End Sub

would work equally as well with a number in the cell.

--
Regards,
Tom Ogilvy
 

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