G
George Gee
Hi all
Is it possible to run a macro by entering data in a cell, and pressing
Enter?
Many thanks
George
Is it possible to run a macro by entering data in a cell, and pressing
Enter?
Many thanks
George
George Gee said:Mangeshh
Thanks for that.
I have:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$N$3" Then
Call AstonAway
End If
End Sub
However, as soon as I select the cell the macro runs.
I need to be able to select the cell, input the data,
*then* run the macro.
Am I doing something wrong?
George Gee
Mangesh said:Don't use
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Use
Private Sub Worksheet_Change(ByVal Target As Range)
as the first line
Mangesh
George Gee said:Mangesh and Bob
Thanks for your continuing help.
I am starting to understand bits of this,
I have thus far: (just using 3 of the 38 macros)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "N3:N40"
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Address
Case "$N$3": Call AstonAway
Case "$N$4": Call EverHome
Case "$N$5": Call NewcasHome
'etc.
End Select
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
But!!!!!
As soon as I try to select say "N3", the macro runs.
This is not what I want.
I have had to change the last action of the macro
to select "N3", or I would not even be able to select it!
Here is a typical macro:
Sub AstonAway()
'
' AstonAway Macro
' Macro recorded 30/07/2004 by George Gee
'
'
Range("E5").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]="""","""",HLOOKUP(RC[-2],'Points
Gained'!R1C5:R40C30,3,FALSE))"
Selection.Copy
Range("E6:E30").Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("E5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AB1:AE1").Select
Selection.Copy
Range("C37:F37").PasteSpecial xlPasteValues
Range("C5:G28").Select
Selection.Sort Key1:=Range("D5"), Order1:=xlDescending,
Key2:=Range("G5") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False, _
Orientation:=xlTopToBottom
Range("N3").Select
End Sub
What is now happening, is that on pressing 'Enter'
The selection moves down one cell, to "N4",
and runs the macro associated with *that* 'Case' !!!
To sum up:
I want to select cell "N3", enter a score, *then* run
the macro associated with that cell.
Regards: George Gee <g>
George Gee said:Thanks Mangesh!
I can see it now!
Although, where *Worksheet_SelectionChange* came from,
I have no idea.
All code has been copied from these posts, (strange).
Sincere appologies for being so dense, and many thanks for
your perseverance.
Thanks Bob
George Gee
Mangesh said:Don't use
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Use
Private Sub Worksheet_Change(ByVal Target As Range)
as the first line
Mangesh
George Gee said:Mangesh and Bob
Thanks for your continuing help.
I am starting to understand bits of this,
I have thus far: (just using 3 of the 38 macros)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "N3:N40"
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Address
Case "$N$3": Call AstonAway
Case "$N$4": Call EverHome
Case "$N$5": Call NewcasHome
'etc.
End Select
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
But!!!!!
As soon as I try to select say "N3", the macro runs.
This is not what I want.
I have had to change the last action of the macro
to select "N3", or I would not even be able to select it!
Here is a typical macro:
Sub AstonAway()
'
' AstonAway Macro
' Macro recorded 30/07/2004 by George Gee
'
'
Range("E5").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]="""","""",HLOOKUP(RC[-2],'Points
Gained'!R1C5:R40C30,3,FALSE))"
Selection.Copy
Range("E6:E30").Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("E5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AB1:AE1").Select
Selection.Copy
Range("C37:F37").PasteSpecial xlPasteValues
Range("C5:G28").Select
Selection.Sort Key1:=Range("D5"), Order1:=xlDescending,
Key2:=Range("G5") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False, _
Orientation:=xlTopToBottom
Range("N3").Select
End Sub
What is now happening, is that on pressing 'Enter'
The selection moves down one cell, to "N4",
and runs the macro associated with *that* 'Case' !!!
To sum up:
I want to select cell "N3", enter a score, *then* run
the macro associated with that cell.
Regards: George Gee <g>
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.