если код - GetAsyncKeyState заменен на MsgBox, он работает нормально, однако, хотя ошибки нет, код не работает с GetAsyncKeyState.
или может ли команда / кнопка переключения работать с EXCEL VBA?
#If VBA7 Then
'declare virtual key event listener
Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
#Else
'declare virtual key event listener
Private Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
#End If
Private Const VK_RA = &H27
Sub Hide_Next()
Dim a As Range
Dim b As Range
Cells.EntireColumn.Hidden = True
Columns("a").EntireColumn.Hidden = False
If GetAsyncKeyState(vbKeyRight) Then
Application.Goto Reference:=Range("a1"), Scroll:=True
For Each a In Range("A2:A23").Cells
If a.Value = Empty Then
a.EntireRow.Hidden = True
End If
Next a
End If
If GetAsyncKeyState(vbKeyRight) Then
Columns("b").EntireColumn.Hidden = False
For Each b In Range("B2:B23").Cells
If b.Value <> Empty Then
b.EntireRow.Hidden = False
End If
Next b
End If
If GetAsyncKeyState(VK_RA) Then
Cells.EntireColumn.Hidden = False
End If
End Sub
Рабочий код, пытается заменить MagBox на нажатие клавиши: Sub Hide_Next ()
Dim a As Range
Dim b As Range
Cells.EntireColumn.Hidden = True
Columns("a").EntireColumn.Hidden = False
MsgBox "Pause-A"
Application.Goto Reference:=Range("a1"), Scroll:=True
For Each a In Range("A2:A23").Cells
If a.Value = Empty Then
a.EntireRow.Hidden = True
End If
Next a
MsgBox "Pause-B"
Columns("b").EntireColumn.Hidden = False
For Each b In Range("B2:B23").Cells
If b.Value <> Empty Then
b.EntireRow.Hidden = False
End If
Next b
'and so on for the next column ...
End Sub
Пример: