Problem with Range selection macro

floridagunner

Board Regular
Joined
Jul 20, 2007
Messages
60
Hello,

I am running the following piece of code in my macro.

Code:
Sub SelectData1()

Set mySelection = Range(ActiveCell, ActiveCell.End(xlDown))
mySelection.Select

End Sub

When I run the above code as a stand alone macro it always works as it should; ie. it selects all the data in the column below the active cell.

However when I'm running it as part of a larger macro instead of selecting the data below the activecell in column R it jumps to selecting all the data in column A.

Anybody have any ideas on how this can be fixed?
 
You do not need to select. For example, change this:

Code:
[LEFT][COLOR=#333333]myRange.Select
[/COLOR][COLOR=#333333]Selection.Font.Bold = True[/COLOR][/LEFT]

into:

Code:
[LEFT][COLOR=#333333]myRange.[/COLOR][COLOR=#333333]Font.Bold = True[/COLOR][/LEFT]

and observe that it works faster, better and with less code.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
floridagunner

ActiveCell isn't what I would call 'unstable' but it is unpredictable when used in code that uses Active/Select.

It's much better to explicitly reference the ranges/worksheets/workbooks you want to work with.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top