Forcing a cell to keep focus

NitherWise

New Member
Joined
Nov 3, 2002
Messages
36
Using VBA, how can you force a cell to stay selected? I have a sheet that I want B3 to stay selected all the time, even after the enter key is pressed. I've tried several variations of code but I can't get it to work.

Thanks,
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Barry Katcher

Well-known Member
Joined
Feb 25, 2002
Messages
4,053
If all you want to do is not have the cell selection change after entry, go into "Tools/Options/Edit" and uncheck the "Move Selection after enter" box. I'm sure you could work this into code.
 

NitherWise

New Member
Joined
Nov 3, 2002
Messages
36
If I do that It affects the whole workbook and I only want to control it on one sheet.

I did try:

Private Sub NoMove()

If Sheets("Control").Range("B3").MoveAfterReturn = True Then
Sheets("Control").Range("B3").MoveAfterReturn = False
End If

End Sub

but that didn't work either.

Can you suggest anything else? Thanks
 
L

Legacy 98055

Guest
Two ways. The first being better in my opinion. Make sure all cells are locked except for the cell in question. Protect the worksheet, and place this code in:

Private Sub Worksheet_Activate()
EnableSelection = xlUnlockedCells
End Sub

Method two:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Target.Address(0, 0) = "B3" Then Range("B3").Select
End Sub

tom
 

Watch MrExcel Video

Forum statistics

Threads
1,123,535
Messages
5,602,217
Members
414,513
Latest member
junbuggle

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
Top