#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 273
Default Macro Button

I have written a macro to change the currency format of certain cells on a
number of different sheets in one workbook. It works when i run it through
tools/macros/ run, but goes into error when i try and run it from a click
button, any ideas
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 112
Default Macro Button

Hello Gary
If you are running code from a commandbutton from the Controls tool box then
consider setting the TakeFocusOnClick property to false.

HTH
Cordially
Pascal

"Gary" a écrit dans le message de news:
...
I have written a macro to change the currency format of certain cells on a
number of different sheets in one workbook. It works when i run it
through
tools/macros/ run, but goes into error when i try and run it from a click
button, any ideas



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 273
Default Macro Button

I still get "select method of range class failed" and highlights the following

Range("E:E,G:G,H:H,I:I,J:J,F24:F26").Select

"papou" wrote:

Hello Gary
If you are running code from a commandbutton from the Controls tool box then
consider setting the TakeFocusOnClick property to false.

HTH
Cordially
Pascal

"Gary" a écrit dans le message de news:
...
I have written a macro to change the currency format of certain cells on a
number of different sheets in one workbook. It works when i run it
through
tools/macros/ run, but goes into error when i try and run it from a click
button, any ideas




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro Button

An unqualifed range will refer to the activesheet if the code is in a general
module.

An unqualified range will refer to the worksheet that owns the code if it's in a
worksheet module.

So if you do:
worksheets("sheet99").select
range("E:E,G:G,H:H,I:I,J:J,F24:F26").select

This will work in a general module. That range will be selected.

But when the code is behind a worksheet, the activesheet is sheet99. But you're
trying to select a range on the sheet that owns the code.

Since you can only select a range on the active sheet, your code bombs.

You could use:

worksheets("sheet99").select
worksheets("sheet99").range("E:E,G:G,H:H,I:I,J:J,F 24:F26").select

or
with worksheets("sheet99")
.select
.range("E:E,G:G,H:H,I:I,J:J,F24:F26").select
End with

But better is to drop the select's and just do the work on the range you want:

worksheets("sheet99").range("E:E,G:G,H:H,I:I,J:J,F 24:F26").numberformat = "0"




Gary wrote:

I still get "select method of range class failed" and highlights the following

Range("E:E,G:G,H:H,I:I,J:J,F24:F26").Select

"papou" wrote:

Hello Gary
If you are running code from a commandbutton from the Controls tool box then
consider setting the TakeFocusOnClick property to false.

HTH
Cordially
Pascal

"Gary" a écrit dans le message de news:
...
I have written a macro to change the currency format of certain cells on a
number of different sheets in one workbook. It works when i run it
through
tools/macros/ run, but goes into error when i try and run it from a click
button, any ideas





--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to button Fritz Excel Discussion (Misc queries) 4 July 22nd 07 05:00 AM
Using Macro to sort without clicking on macro button dd Excel Discussion (Misc queries) 3 May 3rd 07 06:00 PM
Macro Button Lady Success Excel Worksheet Functions 1 November 12th 06 07:13 PM
use macro button to run macro in protected sheet earl Excel Discussion (Misc queries) 3 February 26th 06 10:21 PM
How do I use a macro button momma Excel Discussion (Misc queries) 2 February 5th 06 09:12 AM


All times are GMT +1. The time now is 08:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"