Here's a very simple line of code that will stop users from scrolling about a chosen worksheet. To place the code in, right click on the sheet name tab, select "View Code" and paste in this code.
Private Sub Worksheet_Activate()
Me.ScrollArea = "A1:L20"
'To set back to normal use:
Me.ScrollArea = ""
End Sub
Welcome to VBA Tips & Tricks. All VBA related information will be posted on this blog. Of late, VBA has been disregarded by many software professionals for .Net, c# and other technologies. This blog will also post articles related to them too Happy reading
Monday, April 12, 2010
Making sure the Combobox selection is part of the list:
Private Sub ComboBox1_Change()
If ComboBox1.ListIndex >= 0 Then
'Your code here
End If
End Sub
If ComboBox1.ListIndex >= 0 Then
'Your code here
End If
End Sub
Stop a user from closing a UserForm via the X:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
MsgBox "Please use the Cancel button", vbCritical
End If
End Sub
If CloseMode = 0 Then
Cancel = True
MsgBox "Please use the Cancel button", vbCritical
End If
End Sub
When coding with a UserForm use the keyword Me.
Private Sub UserForm_Activate()
MsgBox Me.Name
End Sub
MsgBox Me.Name
End Sub
When coding with the Worksheet events use the keyword Me.
Private Sub Worksheet_Activate()
MsgBox Me.CodeName
End Sub
MsgBox Me.CodeName
End Sub
When coding with the Workbook events use the keyword Me.
Private Sub Workbook_Open()
MsgBox Me.FullName
End Sub
MsgBox Me.FullName
End Sub
Prevent endless loops within events:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo ResetEvents
Application.EnableEvents = False
'Your code here.
Application.EnableEvents = True
Exit Sub
ResetEvents:
Application.EnableEvents = True
End Sub
On Error GoTo ResetEvents
Application.EnableEvents = False
'Your code here.
Application.EnableEvents = True
Exit Sub
ResetEvents:
Application.EnableEvents = True
End Sub
Subscribe to:
Posts (Atom)