how to remove selection

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
how can i remove the selection from this code, and not get an error? i want to make the changes to the cells but not select those cells. the problem is this selction is running after some other code and it is making the selected cells always return to those cells rather than leaving the active cell the next cell the user selects by hitting enter or a direction likke left or right. so my users have to scroll up all the time. very annoying.
Code:
 Range("D9:E9").Select
      With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
        .Replace What:=Chr(10), Replacement:=""
        End With
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Is it?

Code:
With Range("D9:E9")
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    .Replace What:=Chr(10), Replacement:=""
End With
 
Upvote 0
that works. I want to change that range to say from d9:E and the last row of the range named "activityrange". i dont know how to code finding the last row of the named range of "activityrange".
 
Upvote 0
Does this give you what you want?

Code:
MsgBox Range("activityrange").Cells(Range("activityrange").Rows.Count, 1).Row
 
Upvote 0

Forum statistics

Threads
1,203,501
Messages
6,055,765
Members
444,821
Latest member
Shameer

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