Excel VBA içinde KeyPress tarzý bir olay olmadýðý için kullanýcýnýn bastýðý tuþu yakalaycak bir kod yazamýyoruz. Daha doðrusu dolaylý olarak yazýyoruz.

Application nesnesinin OnKey metodu iþimizi görecek.

Diyelim ki bir hücrede Enter tuþuna basýldýðýnda diðer hücreye günün tarih ve saatini yazsýn istiyoruz.

Yeni bir modül açýyoruz ve bu kodu yapýþtýrýyoruz.

‘Excel açýlýrken Enter tuþu iþlemlerini bir makroya atýyoruz
Private Sub Auto_Open()
Application.OnKey ~, PutDates
Application.OnKey {ENTER}, PutDates
End Sub

‘Excel kapanýrken atamayý kaldýrýyoruz
Private Sub Auto_Close()
Application.OnKey ~
Application.OnKey {ENTER}
End Sub

‘Enter tuþuna basýldýðýnda çalýþacak prosedür
Sub PutDates()
‘Eðer kýsýtlamanýn sadece bir sayfada olmasýný istiyorsak
If ActiveSheet.Name <> bloke Then
ActiveCell.Offset(1, 0).Activate
Exit Sub
End If
If ActiveCell.Value = Then Exit Sub
Select Case ActiveCell.Column
Case 1, 2

‘numaralar duruma göre deðiþtirilebilir. Burada 1. ve 2. sütunlara bakýp 8., 9. ve 10 sütunlara bilgi yazýyoruz
If Cells(ActiveCell.Row, 8).Value = Then
Cells(ActiveCell.Row, 8).Value = Date
End If
If Cells(ActiveCell.Row, ActiveCell.Column + 8).Value = Then
Cells(ActiveCell.Row, ActiveCell.Column + 8).Value = Time
End If
End Select
End Sub

—–

Yorum yapýn?