Numberformat in ADDIN module doesn't work.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Following two functions are used to test change cell value and format. the
dropdown_test function changes the cell setting to dropdown, which works.

The second function tries to change the number format, and expect a
percentage format present. It doesn't work. Hope someone can tell me the
reason why it doesn't work.

Both functions locate in module in a test.xla file and called from Excel
User Defined category.

Function dropdown_test()
ActiveCell.Select
ActiveCell.Clear
With Selection.Validation
.Delete
.Add Type:=xlValidateList, Operator:=xlBetween,
Formula1:="a,b,c,d,e"
.IgnoreBlank = True
.InCellDropdown = True
End With
dropdown_test = "a"
End Function

Function numberformat_pc_test()
ActiveCell.NumberFormat = "0.00"
numberformat_pc_test = 0.234
End Function
 
Thanks Frank.

The active cell number fomat does not change. Always "General".

I expect percentage data come out instead of decimal number, but it still
decimal data come out.

In debug mode, I try change the format in runtime, but it doesn't change.
 
If, in a cell you do

=numberformat_pc_test()

Then functions called in cells (user defined functions) are not allowed to
change the environment such as formatting and so forth. They can only
return a value to the cell in which they are used/called.


I assume you are not doing

=DropDown_test()
 
Thanks Tom.

Dropdown_Test() works fine. That's the reason I put function here to prove
some setting can be changed.
 
So alter Numberformat_pc_test to put data validation in the cell. That is
what you proved worked. Formatting doesn't as I stated.
 

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

Back
Top