ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Sorting Columns Independently Followup From 3/13 (https://www.excelbanter.com/excel-discussion-misc-queries/225172-sorting-columns-independently-followup-3-13-a.html)

curtc.[_2_]

Sorting Columns Independently Followup From 3/13
 
I need to add a line to the macro, so that it only works on a sheet named
"sort". This is so if the short cut to run the macro is run by accident (when
another sheet tab is the current worksheet) it only affects the data on the
"sort" worksheet. How do you identify which sheet of a workbook a macro is
assigned to run in...and that sheet only, even if you are working in another
worksheet (same workbook though)?

Stefi

Sorting Columns Independently Followup From 3/13
 
Insert this line as 1st line of your macro:
Worksheets("sort").Select
Regards,
Stefi


€˛curtc.€¯ ezt Ć*rta:

I need to add a line to the macro, so that it only works on a sheet named
"sort". This is so if the short cut to run the macro is run by accident (when
another sheet tab is the current worksheet) it only affects the data on the
"sort" worksheet. How do you identify which sheet of a workbook a macro is
assigned to run in...and that sheet only, even if you are working in another
worksheet (same workbook though)?


Dave Peterson

Sorting Columns Independently Followup From 3/13
 
I think it would be better to qualify your ranges.

Instead of

range("A1:B99").sort key1:=range("a1"), ...

use

with worksheets("Sort")
.range("a1:B99").sort key1:=.range("A1"), ....
end with

The dots in front of those .Range()'s means that they belong to the object in
the previous with. In this case, that's the Sort worksheet.

If you have trouble adjusting your code, post what you have and I'm sure you'll
get help.

curtc. wrote:

I need to add a line to the macro, so that it only works on a sheet named
"sort". This is so if the short cut to run the macro is run by accident (when
another sheet tab is the current worksheet) it only affects the data on the
"sort" worksheet. How do you identify which sheet of a workbook a macro is
assigned to run in...and that sheet only, even if you are working in another
worksheet (same workbook though)?


--

Dave Peterson


All times are GMT +1. The time now is 11:17 AM.

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