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,
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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