Num Lock ON

annadinesh

Board Regular
Joined
Mar 1, 2017
Messages
123
Office Version
  1. 2019
Platform
  1. Windows
Dear Experts

Please help me out

Num Lock gets OFF always in my vba sheet, Please provide a suggestion so that Num Lock stays always ON in windows 11, Office 2021 & anothet PC with windows 10 and OOffice 2019


Thanks
 

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
Are you using SENDKEYS anywhere in your code by any chance? on some systems, that affects the num lock status.
 
Upvote 0
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error GoTo ErrHandler:
Target.Calculate
If Selection.Cells.Count > 1 Then Exit Sub
If Target.Column = 6 Then oldDate = Target
If Target.Column = 7 Then oldDate = Target
If Target.Column = 8 Then oldDate = Target
If Target.Column = 9 Then oldDate = Target
If Target.Column = 11 Then oldDate = Target

If (GetKeyState(vbKeyShift) And KEY_MASK) <> 0 Then Exit Sub
xOldNLState = GetAsyncKeyState(VK_NUMLOCK)
xOldCLState = GetAsyncKeyState(VK_CAPITAL)
xOldSLState = GetAsyncKeyState(VK_SCROLL)

If Not Intersect(Target, Range("M4:M65536")) Is Nothing Then
SendKeys "{F2}"

If GetAsyncKeyState(VK_NUMLOCK) <> xOldNLState Then
Application.SendKeys "{NUMLOCK}"
End If
If GetAsyncKeyState(VK_CAPITAL) <> xOldCLState Then
Application.SendKeys "{CAPSLOCK}"
End If
If GetAsyncKeyState(VK_SCROLL) <> xOldSLState Then
Application.SendKeys "{SCROLLLOCK}"

SendKeys "{NUMLOCK}{NUMLOCK}"
End If
End If
If Target.Cells.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("A4:P65536")) Is Nothing Then

Range("A4:P65536").Interior.Color = xlNone
Range(Cells(Target.Row, "A"), Cells(Target.Row, "P")).Interior.Color = RGB(255, 215, 0)
Target.Interior.ColorIndex = 37
End If


If Target.Column = 17 Then
Target.Offset(0, -16).Select
End If

If Target.Column = 10 Then
If Range("L" & (ActiveCell.Row)).Value = "" Then
Target.Offset(0, 2).Select
Else
Target.Offset(0, -9).Select
End If
End If

What for? SENDKEYS is a last resort command and hardly ever necessary.
 
Upvote 0
I see this code puts Excel in cell edit mode as soon as the user selects a cell in column M. This is one of those cases you can only achieve with sendkeys. I've never been able to resolve the num lock issue either, despite countless efforts similar to yours. I decided to give up :)
 
Upvote 0

Forum statistics

Threads
1,221,510
Messages
6,160,226
Members
451,632
Latest member
purpleflower26

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