displaying text & variable information in cell

P

pallaver

I have two variables taken from textboxes on a userform: XPosVariance
& XNegVariance

I want to have them displayed in a cell when clicking done on the
userform such that the cell reads:

+5/-8

(In the case that XPosVariance = 5 and XNegVariance = 8).

I have this:

Sheets("´£¥X¥Î").Cells(SokuteiItemRow, SokuteiItemColumn + 2).Value = "+"
& (XPosVariance) & "/-" (XNegVariance)

But it doesn't work. I'm sure the variables are fine because as a
test I just wrote = "TEST" and I get "TEST" written in the correct
spot. Any way I can do the above? I have a feeling this isn't a
tough question, I just don't know how to do it.

Thankx.
 
M

Mike

Maybe this
Sheets("???").Cells(SokuteiItemRow, SokuteiItemColumn + 2).Value = _
Format("+" & (XPosVariance) & "/-" & (XNegVariance), "@")
 
P

pallaver

BAM! On the money.

Sorry for the ???, I'm working on macros in Japan, thus have sheet
names in Japanese which probably don't convert. This site is a
lifesaver since it's really hard to figure out the help function
entirely in Japanese.

One question though, why is "@" necessary at the end? I wonder if it
works without it.

Thanks.
 
M

Mike

If you record a macro formatting a cell to text. That is what it records. "@"
Try it.
 
M

Mike

And yes it will work with out it.

pallaver said:
BAM! On the money.

Sorry for the ???, I'm working on macros in Japan, thus have sheet
names in Japanese which probably don't convert. This site is a
lifesaver since it's really hard to figure out the help function
entirely in Japanese.

One question though, why is "@" necessary at the end? I wonder if it
works without it.

Thanks.
 
P

pallaver

I know how to record a macro, but don't know how to record one
formatting a cell to text. What would I type in the cell when the
macro is recording?

--- MIKE WROTE ---
If you record a macro formatting a cell to text. That is what it
records. "@" Try it.
 
M

Mike

Just right-click on a cell. Select Format Cells... Select Text as the format.
Thats it.
 
R

Rick Rothstein \(MVP - VB\)

In looking at the code line, I don't see why the Format function call is
needed at all... it looks like a simple concatenation and cell assignment to
me.

To the OP.... does this modified statement work also?

Sheets("???").Cells(SokuteiItemRow, SokuteiItemColumn + 2).Value = _
"+" & XPosVariance & "/-" & XNegVariance

Rick
 
P

pallaver

Nope, sorry Rick. That doesn't work. I get an error. I tried adding
parenthesis around the variables as well, but similar to above, NG.

I'm stuck on my macro now on some execution error 13, non-agreement
with bodies.... argh...
 
D

Dave Peterson

You never shared what those row and column values were.

I'd use one of these just to make sure that the value is treated like text.

Later, if you edit that cell (that's formatted as General), you may find that
your text expression has changed to a formula. And I don't know if you want
that.

Sheets("Sheet1").Cells(SokuteiItemRow, SokuteiItemColumn + 2).Value _
= "'+" & XPosVariance & "/-" & xNegVariance

(notice the apostrophe in front of the plus)

or

with Sheets("Sheet1").Cells(SokuteiItemRow, SokuteiItemColumn + 2)
.numberformat = "@" 'text
.Value = "+" & XPosVariance & "/-" & xNegVariance
end with
 

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