A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How do I get a macro to be non worksheet specific?



 
 
Thread Tools Display Modes
  #1  
Old January 4th, 2010, 08:47 PM posted to microsoft.public.excel.worksheet.functions
navel151
external usenet poster
 
Posts: 14
Default How do I get a macro to be non worksheet specific?

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.
  #2  
Old January 4th, 2010, 08:54 PM posted to microsoft.public.excel.worksheet.functions
trip_to_tokyo[_3_]
external usenet poster
 
Posts: 932
Default How do I get a macro to be non worksheet specific?

In EXCEL 2007:-

When you record your Macro for the first time you will get the Macro panel
up (where you name it).

In here there is a section called:-

Store macro in:

It is here that you can select one of the options to make the macro
available outside of that Workbook only.

Please hit yes if my comments have helped.

Thanks.

"navel151" wrote:

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.

  #3  
Old January 4th, 2010, 09:14 PM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
Default How do I get a macro to be non worksheet specific?

No different than previous versions of Excel.

Use ActiveSheet in your code.

e.g. ActiveSheet.Range("A1:A10").Interior.ColorIndex = 3

more specific to your needs............

ActiveSheet.Columns("C:F").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=2, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


Gord Dibben MS Excel MVP

On Mon, 4 Jan 2010 12:47:01 -0800, navel151
wrote:

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.


  #4  
Old January 4th, 2010, 09:24 PM posted to microsoft.public.excel.worksheet.functions
Eva
external usenet poster
 
Posts: 316
Default How do I get a macro to be non worksheet specific?

This in an example. Change sort key1 range to whatever you need

Sub Macro2()
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Click yes if it helped.
--
Greatly appreciated
Eva


"navel151" wrote:

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.

  #5  
Old January 4th, 2010, 09:25 PM posted to microsoft.public.excel.worksheet.functions
JLatham
external usenet poster
 
Posts: 1,896
Default How do I get a macro to be non worksheet specific?

When you record a macro that does something like sorting, typically it
annotates the specific sheet that was active when you recorded it. Also it
will do something like selecting the cells you want to take action on. These
are both things you probably don't want in your 'generic' macro. So you
might end up with code that looks something like this:
Sub Macro1()
Sheets("Sheet1").Select
Range("B24").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select
End Sub

The first thing to do away with would be the Sheets("Sheet1").Select
statement. Then (here's the answer to your question), set up a couple of
range variables to use as part of the sort
Dim sRange as Range
Dim sKey as Range

and set them to the current ActiveSheet!!And modify the code accordingly:

Set sRange=ActiveSheet.Range("B24")
Set sKey = ActiveSheet.Range("B2")
sRange.Sort Key1:=sKey, Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

And you're done with it.

"navel151" wrote:

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.

  #6  
Old January 4th, 2010, 09:30 PM posted to microsoft.public.excel.worksheet.functions
ryguy7272
external usenet poster
 
Posts: 1,593
Default How do I get a macro to be non worksheet specific?

Some good resources:
http://www.anthony-vba.kefra.com/vba/vbabasic1.htm
http://www.rondebruin.nl/code.htm
http://www.contextures.com/xlvba01.html

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"JLatham" wrote:

When you record a macro that does something like sorting, typically it
annotates the specific sheet that was active when you recorded it. Also it
will do something like selecting the cells you want to take action on. These
are both things you probably don't want in your 'generic' macro. So you
might end up with code that looks something like this:
Sub Macro1()
Sheets("Sheet1").Select
Range("B24").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select
End Sub

The first thing to do away with would be the Sheets("Sheet1").Select
statement. Then (here's the answer to your question), set up a couple of
range variables to use as part of the sort
Dim sRange as Range
Dim sKey as Range

and set them to the current ActiveSheet!!And modify the code accordingly:

Set sRange=ActiveSheet.Range("B24")
Set sKey = ActiveSheet.Range("B2")
sRange.Sort Key1:=sKey, Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

And you're done with it.

"navel151" wrote:

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.

  #7  
Old January 4th, 2010, 09:46 PM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
Default How do I get a macro to be non worksheet specific?

How will that make the macro non-sheet specific?


Gord

On Mon, 4 Jan 2010 12:54:02 -0800, trip_to_tokyo
wrote:

In EXCEL 2007:-

When you record your Macro for the first time you will get the Macro panel
up (where you name it).

In here there is a section called:-

Store macro in:

It is here that you can select one of the options to make the macro
available outside of that Workbook only.

Please hit yes if my comments have helped.

Thanks.

"navel151" wrote:

I can't figure out how to make a macro non worksheet specific like they were
in previous versions of Excel. I want to have a macro that will sort the
same range of cells of whatever sheet that I am in, rather than having the
same macro for each sheet with a different name.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:36 PM.


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