Thread: cell formatting
View Single Post
  #14   Report Post  
Darryl
 
Posts: n/a
Default

Well, maybe isn't not a type mis-match. When I try to enter data in the
field and then leave it,
nothing happens (ie, 1.2 gets set to 120%). When I debug the macro it gives
an error saying that
the macro tries to access a protected area of the document. If I unprotect
the document, (ie, not a form), then nothing happens (as described above).


"Darryl" wrote in message
...
Well,
I changed Value1 to my field name.
I have the field set as number, format 0.00%, macro on exit is
divide100.

When I run it, I get a type mismatch error. Looking at the macro,
I'm not sure why ? Form field is type number. Is the macro assuming
the field is text ?


"Jean-Guy Marcil" wrote in message
...
Darryl was telling us:
Darryl nous racontait que :

Thanks Anne.

I understand that 8.7 is not 8.7%. But as the users say, I need it
this way.
I don't know how to make it such that when the user leaves the field
in the table, that the resulting value (870%) is divided by 100 so it
shows 8.7% (the goal).


Here is a little macro that does that:

'_______________________________________
Sub Divide100()

Dim myValue As Single

With ActiveDocument.Bookmarks("Value1").Range
myValue = CSng(Left(.Text, Len(.Text) - 1))
myValue = myValue / 10000
.FormFields(1).Result = CStr(myValue)

End With

End Sub

'_______________________________________

Note that I have to divide by 10 000 because when I do the calculation,

the
number entered by the user a=has already been multiplied by a 100

because
of
the number format...

The formfield name is Value1.
Either change the name in the macro, or change it in the form itself.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org