Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 73
Default How to Run a Macro from clicking a cell

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default How to Run a Macro from clicking a cell

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 73
Default How to Run a Macro from clicking a cell

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1


"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to Run a Macro from clicking a cell

Try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

if target.cells.count 1 then exit sub 'single cell at a time

if lcase(target.value) = lcase("Print KS2") Then
call Printks2
End If

End Sub

You don't need the word "call", but it doesn't hurt. I like it because it's
self-documenting (to me, anyway).

The real problem is that excel doesn't have a single click event. The
worksheet_selectionchange event fires when you select the cell (either by using
the keyboard arrows or single clicking in the cell).

If you want to use double clicking, then you want to use a different event.

Try:

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)

If Target.Cells.Count 1 Then Exit Sub 'single cell at a time

If LCase(Target.Value) = LCase("Print KS2") Then
Cancel 'stop that editing
Call Printks2
End If

End Sub

(remove the worksheet_selection procedure.


Romileyrunner1 wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1

"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 73
Default How to Run a Macro from clicking a cell

Thanks Dave,
Tried this and still no joy: in fact other macros started to have problems.
You mentioned `double clicking` being a `different event`: quite happy o use
double clicking in a cell to begin the macro if that might work.
Thanks.
RR1

"Dave Peterson" wrote:

Try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

if target.cells.count 1 then exit sub 'single cell at a time

if lcase(target.value) = lcase("Print KS2") Then
call Printks2
End If

End Sub

You don't need the word "call", but it doesn't hurt. I like it because it's
self-documenting (to me, anyway).

The real problem is that excel doesn't have a single click event. The
worksheet_selectionchange event fires when you select the cell (either by using
the keyboard arrows or single clicking in the cell).

If you want to use double clicking, then you want to use a different event.

Try:

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)

If Target.Cells.Count 1 Then Exit Sub 'single cell at a time

If LCase(Target.Value) = LCase("Print KS2") Then
Cancel 'stop that editing
Call Printks2
End If

End Sub

(remove the worksheet_selection procedure.


Romileyrunner1 wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1

"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to Run a Macro from clicking a cell

I don't understand. Which version of the code didn't work?

Romileyrunner1 wrote:

Thanks Dave,
Tried this and still no joy: in fact other macros started to have problems.
You mentioned `double clicking` being a `different event`: quite happy o use
double clicking in a cell to begin the macro if that might work.
Thanks.
RR1

"Dave Peterson" wrote:

Try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

if target.cells.count 1 then exit sub 'single cell at a time

if lcase(target.value) = lcase("Print KS2") Then
call Printks2
End If

End Sub

You don't need the word "call", but it doesn't hurt. I like it because it's
self-documenting (to me, anyway).

The real problem is that excel doesn't have a single click event. The
worksheet_selectionchange event fires when you select the cell (either by using
the keyboard arrows or single clicking in the cell).

If you want to use double clicking, then you want to use a different event.

Try:

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)

If Target.Cells.Count 1 Then Exit Sub 'single cell at a time

If LCase(Target.Value) = LCase("Print KS2") Then
Cancel 'stop that editing
Call Printks2
End If

End Sub

(remove the worksheet_selection procedure.


Romileyrunner1 wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1

"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to Run a Macro from clicking a cell

Dave included the doubleclick event code in his post.

Delete the selectionchange event code and replace with the doubleclick code.


Gord Dibben MS Excel MVP

On Sat, 19 Sep 2009 10:53:01 -0700, Romileyrunner1
wrote:

Thanks Dave,
Tried this and still no joy: in fact other macros started to have problems.
You mentioned `double clicking` being a `different event`: quite happy o use
double clicking in a cell to begin the macro if that might work.
Thanks.
RR1

"Dave Peterson" wrote:

Try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

if target.cells.count 1 then exit sub 'single cell at a time

if lcase(target.value) = lcase("Print KS2") Then
call Printks2
End If

End Sub

You don't need the word "call", but it doesn't hurt. I like it because it's
self-documenting (to me, anyway).

The real problem is that excel doesn't have a single click event. The
worksheet_selectionchange event fires when you select the cell (either by using
the keyboard arrows or single clicking in the cell).

If you want to use double clicking, then you want to use a different event.

Try:

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)

If Target.Cells.Count 1 Then Exit Sub 'single cell at a time

If LCase(Target.Value) = LCase("Print KS2") Then
Cancel 'stop that editing
Call Printks2
End If

End Sub

(remove the worksheet_selection procedure.


Romileyrunner1 wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1

"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default How to Run a Macro from clicking a cell

Hi RR1,

The "SelectionChange" part of the statement refers to any movemen twhen you
move from the the cuurent cell... The command then works on the ACTIVE cell.
need the word "maro" after .. you do not need the wor macro after Printks2...
to be 100% correct you could say :

If ActiveCell.Value = "Print KS2" Then
call Printks2
End If


hope this helps..

Regards

Les
"Romileyrunner1" wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1


"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1


  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default How to Run a Macro from clicking a cell

sorry my keyboard (and the fact that I have been watching rugby) are not
conducive to coherent sentences... the remarks bellow sould have been...

The "SelectionChange" part of the statement refers to any movement when you
move from the the cuurent cell in a workbook... The command then works on
the ACTIVECELL statement.

You MUDT not use the word "maro" after Printks2...

To be 100% correct you could say :
If ActiveCell.Value = "Print KS2" Then
call Printks2
End If


"LesG" wrote:

Hi RR1,

The "SelectionChange" part of the statement refers to any movemen twhen you
move from the the cuurent cell... The command then works on the ACTIVE cell.
need the word "maro" after .. you do not need the wor macro after Printks2...
to be 100% correct you could say :

If ActiveCell.Value = "Print KS2" Then
call Printks2
End If


hope this helps..

Regards

Les
"Romileyrunner1" wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1


"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1


  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to Run a Macro from clicking a cell

Actually, I wouldn't use Activecell.

I'd use the variable that was passed to the procedure (Target). And I'd make
sure that the case didn't matter:


if lcase(Target.value) = lcase("print ks2") then



LesG wrote:

sorry my keyboard (and the fact that I have been watching rugby) are not
conducive to coherent sentences... the remarks bellow sould have been...

The "SelectionChange" part of the statement refers to any movement when you
move from the the cuurent cell in a workbook... The command then works on
the ACTIVECELL statement.

You MUDT not use the word "maro" after Printks2...

To be 100% correct you could say :
If ActiveCell.Value = "Print KS2" Then
call Printks2
End If

"LesG" wrote:

Hi RR1,

The "SelectionChange" part of the statement refers to any movemen twhen you
move from the the cuurent cell... The command then works on the ACTIVE cell.
need the word "maro" after .. you do not need the wor macro after Printks2...
to be 100% correct you could say :

If ActiveCell.Value = "Print KS2" Then
call Printks2
End If


hope this helps..

Regards

Les
"Romileyrunner1" wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1


"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default How to Run a Macro from clicking a cell

Hi Dave... this is quite handy. Am I correct in assuming that the
"lcase(Target.value)" forces the target value to be lowercase?

"Dave Peterson" wrote:

Actually, I wouldn't use Activecell.

I'd use the variable that was passed to the procedure (Target). And I'd make
sure that the case didn't matter:


if lcase(Target.value) = lcase("print ks2") then



LesG wrote:

sorry my keyboard (and the fact that I have been watching rugby) are not
conducive to coherent sentences... the remarks bellow sould have been...

The "SelectionChange" part of the statement refers to any movement when you
move from the the cuurent cell in a workbook... The command then works on
the ACTIVECELL statement.

You MUDT not use the word "maro" after Printks2...

To be 100% correct you could say :
If ActiveCell.Value = "Print KS2" Then
call Printks2
End If

"LesG" wrote:

Hi RR1,

The "SelectionChange" part of the statement refers to any movemen twhen you
move from the the cuurent cell... The command then works on the ACTIVE cell.
need the word "maro" after .. you do not need the wor macro after Printks2...
to be 100% correct you could say :

If ActiveCell.Value = "Print KS2" Then
call Printks2
End If


hope this helps..

Regards

Les
"Romileyrunner1" wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1


"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson

  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to Run a Macro from clicking a cell

exactly.

Then "print ks2" will be treated the same as "PrinT KS2" or "PRINT ks2" or ...

LesG wrote:

Hi Dave... this is quite handy. Am I correct in assuming that the
"lcase(Target.value)" forces the target value to be lowercase?

"Dave Peterson" wrote:

Actually, I wouldn't use Activecell.

I'd use the variable that was passed to the procedure (Target). And I'd make
sure that the case didn't matter:


if lcase(Target.value) = lcase("print ks2") then



LesG wrote:

sorry my keyboard (and the fact that I have been watching rugby) are not
conducive to coherent sentences... the remarks bellow sould have been...

The "SelectionChange" part of the statement refers to any movement when you
move from the the cuurent cell in a workbook... The command then works on
the ACTIVECELL statement.

You MUDT not use the word "maro" after Printks2...

To be 100% correct you could say :
If ActiveCell.Value = "Print KS2" Then
call Printks2
End If

"LesG" wrote:

Hi RR1,

The "SelectionChange" part of the statement refers to any movemen twhen you
move from the the cuurent cell... The command then works on the ACTIVE cell.
need the word "maro" after .. you do not need the wor macro after Printks2...
to be 100% correct you could say :

If ActiveCell.Value = "Print KS2" Then
call Printks2
End If


hope this helps..

Regards

Les
"Romileyrunner1" wrote:

Hi, LesG

Can you see what I`m doing wrong? It doesn`t seem to be woking for me!
I`ve typed the following along with my other macros.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "Print KS2" Then
Printks2 Macro
End If
End Sub

Printks2 is the name of the macro I want to use. (should I not put the word
Macro after it?)
I have entered Print KS2 in a blank cell.
When I double click in it, it just wants to edit the typing.
Do I need to do something else to that cell?

Also, because the Macro begins "Private Sub Worksheet..." will others be
able to use this; is it part of this worksheet?

Thanks, LesG

RR1


"LesG" wrote:

assuming you are going to replace controls (buttons) with lables in cells,
press Alt F11 an insert (and amend) the following in the worksheet...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Value = "value in cell" Then
macroname
End If
End Sub

hope this helps, if so click yes

"Romileyrunner1" wrote:

Hi,
have a number of macros wrtten that are currently activated by buttons on
top of cells.
Here is one such macro:
Sub Printall()
'
' Printall Macro
' Macro recorded 17/09/2009 by User
'

'
Range("A10:CF53").Select
ActiveSheet.PageSetup.PrintArea = "$A$10:$CF$53"
Range("A1").Select
End Sub

How do I use this to now change to just a cell (double-click) activated macro?
Do I enter the sheet name and cell reference somewhere?
Have read the following from an earlier question but frankly don`t follow
it!!! Sorry


The following in the Worksheet Selection Change event should do the
trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then Range("B4")
="24"

End Sub

Thanks
RR1



--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clicking on cell asek71 Excel Discussion (Misc queries) 2 August 1st 08 06:43 PM
Run a macro when clicking a cell. [email protected] Excel Worksheet Functions 9 May 7th 08 08:58 AM
Run a macro after clicking into cell Esradekan Excel Worksheet Functions 6 March 27th 08 10:34 PM
Using Macro to sort without clicking on macro button dd Excel Discussion (Misc queries) 3 May 3rd 07 06:00 PM
Run macro from clicking on a cell jrd269 Excel Discussion (Misc queries) 2 June 3rd 05 09:35 PM


All times are GMT +1. The time now is 06:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"