Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Macro to Cell

How do I assign a macro to a cell so that when one clicks on it a Listbox
opens or a macro runs?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Macro to Cell

Hi,
You could use the Worksheet_SelectionChange event.

For example, assuming the cell to be D10

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address="$D$10" then
MsgBox Target.Address
End If
End Sub

or using row and column numbers
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 10 And Target.Column = 4 Then
MsgBox Target.Address
End If
End Sub

In place of the MsgBox, you could enter code or call a macro.

Hope that gets you started.
Don

"Ronbo" wrote in message
...
How do I assign a macro to a cell so that when one clicks on it a Listbox
opens or a macro runs?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Macro to Cell



"Don Lloyd" wrote:

Hi,
You could use the Worksheet_SelectionChange event.

For example, assuming the cell to be D10

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address="$D$10" then
MsgBox Target.Address
End If
End Sub

or using row and column numbers
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 10 And Target.Column = 4 Then
MsgBox Target.Address
End If
End Sub

In place of the MsgBox, you could enter code or call a macro.

Hope that gets you started.
Don

"Ronbo" wrote in message
...
How do I assign a macro to a cell so that when one clicks on it a Listbox
opens or a macro runs?

Thanks




I want the click on the cell to call a ListBox. Where does the "Private Sub
Worksheet" go?? In the UserForm/ListBox code, in the sheet or where??

Thanks for your help.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Macro to Cell

For a list box you could use data validation.
Go to: Data Validation...
Select list from the Allow: box
In the Source: box select the range with the data you need for the
user's selection.
Hit OK


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Macro to Cell



"Claud Balls" wrote:

For a list box you could use data validation.
Go to: Data Validation...
Select list from the Allow: box
In the Source: box select the range with the data you need for the
user's selection.
Hit OK


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


That is a cool function, but it can only ref one column. Second, is it
possible to make it dynamic so that it changes with the list size?


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Macro to Cell

The Sub goes in the Worksheet Module

Right-click the sheet tab and select View Code.
Select Worksheet in the left column and SelectioChange in the right column

regards,
Don

"Ronbo" wrote in message
...


"Don Lloyd" wrote:

Hi,
You could use the Worksheet_SelectionChange event.

For example, assuming the cell to be D10

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address="$D$10" then
MsgBox Target.Address
End If
End Sub

or using row and column numbers
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 10 And Target.Column = 4 Then
MsgBox Target.Address
End If
End Sub

In place of the MsgBox, you could enter code or call a macro.

Hope that gets you started.
Don

"Ronbo" wrote in message
...
How do I assign a macro to a cell so that when one clicks on it a
Listbox
opens or a macro runs?

Thanks




I want the click on the cell to call a ListBox. Where does the "Private
Sub
Worksheet" go?? In the UserForm/ListBox code, in the sheet or where??

Thanks for your help.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro to Cell


"Ronbo" wrote in message
...

That is a cool function, but it can only ref one column. Second, is it
possible to make it dynamic so that it changes with the list size?


If we assume the list is in A1:An, use this formula with the DV list

=OFFSET($A$1,,,COUNTA($A:$A))


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
'IF' Macro to insert cell contents to alternate cell if cell not e Gryndar Excel Worksheet Functions 6 December 20th 08 05:02 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
macro to run a separate macro dependent on value in cell scottwilsonx[_13_] Excel Programming 3 July 26th 04 02:30 PM
Please help! Macro to change cell contents based on cell to the left Jennifer[_8_] Excel Programming 7 March 4th 04 01:06 AM
Question: Cell formula or macro to write result of one cell to another cell Frederik Romanov Excel Programming 1 July 8th 03 03:03 PM


All times are GMT +1. The time now is 02:18 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"