ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to change number format of a highlighted range in Excel 2007 (https://www.excelbanter.com/excel-programming/409819-macro-change-number-format-highlighted-range-excel-2007-a.html)

Lauren977

macro to change number format of a highlighted range in Excel 2007
 
I was using the following macro to change the number format of a highlighted
range.

Selection.NumberFormat = "#,##0"

In Excel 97 and 2000 it was working fine. In Excel 2007 it is giving me the
following error message:

Run-time error '1004'
Unable to set the NumberProperty of the range class

I am stumped and haven't been able to find any documentation on this change.



Dave Peterson

macro to change number format of a highlighted range in Excel 2007
 
Is the worksheet protected?



Lauren977 wrote:

I was using the following macro to change the number format of a highlighted
range.

Selection.NumberFormat = "#,##0"

In Excel 97 and 2000 it was working fine. In Excel 2007 it is giving me the
following error message:

Run-time error '1004'
Unable to set the NumberProperty of the range class

I am stumped and haven't been able to find any documentation on this change.


--

Dave Peterson

Lauren977

macro to change number format of a highlighted range in Excel
 
Hi Dave,

Yes the worksheet is protected, but I am running a routine to remove the
protection. This routine is the same as in my other macros and is working
the

If ActiveSheet.Protect = True Then ActiveSheet.Unprotect Password:="percy"

Thanks for getting back to me quickly.

Lauren

"Dave Peterson" wrote:

Is the worksheet protected?



Lauren977 wrote:

I was using the following macro to change the number format of a highlighted
range.

Selection.NumberFormat = "#,##0"

In Excel 97 and 2000 it was working fine. In Excel 2007 it is giving me the
following error message:

Run-time error '1004'
Unable to set the NumberProperty of the range class

I am stumped and haven't been able to find any documentation on this change.


--

Dave Peterson


Dave Peterson

macro to change number format of a highlighted range in Excel
 
If you want to check for protection, you should use something like:

With ActiveSheet
If .ProtectContents = True _
Or .ProtectDrawingObjects = True _
Or .ProtectScenarios = True Then
.Unprotect Password:="percy"
end if
end with

But I bet excel will forgive you if you just unprotect it without checking:

ActiveSheet.Unprotect Password:="percy"



Lauren977 wrote:

Hi Dave,

Yes the worksheet is protected, but I am running a routine to remove the
protection. This routine is the same as in my other macros and is working
the

If ActiveSheet.Protect = True Then ActiveSheet.Unprotect Password:="percy"

Thanks for getting back to me quickly.

Lauren

"Dave Peterson" wrote:

Is the worksheet protected?



Lauren977 wrote:

I was using the following macro to change the number format of a highlighted
range.

Selection.NumberFormat = "#,##0"

In Excel 97 and 2000 it was working fine. In Excel 2007 it is giving me the
following error message:

Run-time error '1004'
Unable to set the NumberProperty of the range class

I am stumped and haven't been able to find any documentation on this change.


--

Dave Peterson


--

Dave Peterson

Lauren977

macro to change number format of a highlighted range in Excel
 
Thanks Dave,

That works great! You have saved me a huge amount of trial and error.

Lauren

"Dave Peterson" wrote:

If you want to check for protection, you should use something like:

With ActiveSheet
If .ProtectContents = True _
Or .ProtectDrawingObjects = True _
Or .ProtectScenarios = True Then
.Unprotect Password:="percy"
end if
end with

But I bet excel will forgive you if you just unprotect it without checking:

ActiveSheet.Unprotect Password:="percy"



Lauren977 wrote:

Hi Dave,

Yes the worksheet is protected, but I am running a routine to remove the
protection. This routine is the same as in my other macros and is working
the

If ActiveSheet.Protect = True Then ActiveSheet.Unprotect Password:="percy"

Thanks for getting back to me quickly.

Lauren

"Dave Peterson" wrote:

Is the worksheet protected?



Lauren977 wrote:

I was using the following macro to change the number format of a highlighted
range.

Selection.NumberFormat = "#,##0"

In Excel 97 and 2000 it was working fine. In Excel 2007 it is giving me the
following error message:

Run-time error '1004'
Unable to set the NumberProperty of the range class

I am stumped and haven't been able to find any documentation on this change.

--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com