Limit location of Highlighted/Active Cell

EssKayKay

Board Regular
Joined
Jan 5, 2003
Messages
233
Office Version
  1. 2007
Platform
  1. Windows
I’m not sure this is possible but is there a way to limit the range where an active cell is allowed? I’m not talking about “locking” a cell, I mean where you can only highlight/activate cells in a specific range (M33:M1233), either using the mouse or tab/enter button.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You could do this with VBA in the Worksheet, Selection Change event.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim lngTargetRow As Long

    If Intersect(Target, Range("M33:M1233")) Is Nothing Then

        Application.EnableEvents = False

        lngTargetRow = Target.Row

        If lngTargetRow < 33 Then
            lngTargetRow = 33
        ElseIf lngTargetRow > 1233 Then
            lngTargetRow = 1233
        End If

        Range("M" & lngTargetRow).Select

        Application.EnableEvents = True

    End If

End Sub

If the user hits the TAB key, it will likely stay in the same cell, but arrows, ENTER, or mouse should all work. There is likely a way to handle the TAB key, but I cannot think of it at the moment.

Hope that helps,

Doug
 
Upvote 0
OOPS - Apparently I made a duplicate entry.
You could do this with VBA in the Worksheet, Selection Change event.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim lngTargetRow As Long

    If Intersect(Target, Range("M33:M1233")) Is Nothing Then

        Application.EnableEvents = False

        lngTargetRow = Target.Row

        If lngTargetRow < 33 Then
            lngTargetRow = 33
        ElseIf lngTargetRow > 1233 Then
            lngTargetRow = 1233
        End If

        Range("M" & lngTargetRow).Select

        Application.EnableEvents = True

    End If

End Sub

If the user hits the TAB key, it will likely stay in the same cell, but arrows, ENTER, or mouse should all work. There is likely a way to handle the TAB key, but I cannot think of it at the moment.

Hope that helps,

Doug
Thank you Doug. I am still having a problem with this. BUT, I thought of something else. I can hide column H with a command button etc. The run my program and upon exit unhide the column. This is working quite well. The problem is I have numerous other buttons that are now in the way. So I added a hide for the buttons which again is working. But now I have shapes behind the buttons that I do not know how to either hide or reshape.

Is there a way to either hide or rather resize a shape? This way after hiding column H, I could resize the shape to fit the screen properly. After that I would unhide the buttons and return the shape to it's original size (or unhide the shape).

Again thanks,
Steve,
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,378
Members
449,097
Latest member
Jabe

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