roi santos
Board Regular
- Joined
- Oct 3, 2008
- Messages
- 57
I would like a to activate a form every time I click in a given cell. Does somebody knows how to do this?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then Call YourMacroNameHere 'amend the address to the be cell you want, and YourmAcroNameHere to be the macro you want to activate
End Sub
if target.address="$A$1" then
'code here
end if
If you right click on the tab of the worksheet where the cell lives, and choose 'view code', you can create a macro which will activate whenever a specific event occurs on the sheet.
If you select 'worksheet' from the left listbox and either 'beforerightclick' or 'beforedoubleclick' from the right one, it will create a bare subroutine for you to enter the code.
The 'target' parameter is the range of the cell clicked, so if your code was reliant on a1, you could use
Code:if target.address="$A$1" then 'code here end if
You can show a userform by calling it's name with a .show on the end
so if your form is called 'userform1' then
userform1.show
HTH
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$E$3" Then
Call View_AMS
End If
If Target.Address = "$E$4" Then
Call View_BAR
End If
If Target.Address = "$E$5" Then
Call View_BRU
End If
If Target.Address = "$E$6" Then
Call View_BSL
End If
If Target.Address = "$E$7" Then
Call View_CRI_1
End If
Dim site As String
site = ActiveCell
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim site As String
site = ActiveCell
Dim pro As String
pro = "view_" + site
Application.Run pro
End Sub
it reacts ALL the time on ALL cells from the worksheet.
Is there a way to limit only to 1 column?
If Target.Column = 5 And Target.Count = 1 Then
'your code
'your code
End If
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 4 Then
Dim site As String
site = ActiveCell
Sheets(site).Select
End If
End Sub
Thank you again for any help
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 4 And Target.Cells(1, 1).Value <> "" Then
Sheets(Target.Cells(1, 1).Value).Select
End If
End Sub