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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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