Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't change NumberFormat via Command button
I have a piece of code as follows :
Dim myCell as Range For Each myCell in Selection MyCell.NumberFormat = "@" Next myCell When I select a range of cells manually and run the macro from the <Tools menu in Excel '97, it works fine but the problem is that if I put this code in a button_click Sub, I get the error message 'Unable to change the NumberFormat property of the Range Object' for the code 'myCell.NumberFormat = "@". Could someone suggest a reason(s) as to why this happens, I am completely dumbfounded. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't change NumberFormat via Command button
Rightclick on the commandbutton
choose properties Change the .takefocusonclick property to false This bug was fixed in xl2k. ps. why not get all the cells at once and drop the loop: Selection.numberformat = "@" Ade wrote: I have a piece of code as follows : Dim myCell as Range For Each myCell in Selection MyCell.NumberFormat = "@" Next myCell When I select a range of cells manually and run the macro from the <Tools menu in Excel '97, it works fine but the problem is that if I put this code in a button_click Sub, I get the error message 'Unable to change the NumberFormat property of the Range Object' for the code 'myCell.NumberFormat = "@". Could someone suggest a reason(s) as to why this happens, I am completely dumbfounded. -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't change NumberFormat via Command button
Cheers Dave, I'll give that a go later and if it works I'll be a happy man.
I have tried theSelection.NumberFormat method you suggested as well but the same thing was happening. Thanks again. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't change NumberFormat via Command button
Change that .takefocusonclick property--no matter which version you use.
Ade wrote: Cheers Dave, I'll give that a go later and if it works I'll be a happy man. I have tried theSelection.NumberFormat method you suggested as well but the same thing was happening. Thanks again. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Change color of command button | Excel Discussion (Misc queries) | |||
How to change the default Command Button | Excel Programming | |||
using vba to change command button caption | Excel Programming | |||
CHANGE DATA SERIES WITH A COMMAND BUTTON | Charts and Charting in Excel | |||
Change Name of Command Button | Excel Discussion (Misc queries) |