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


This is a question that may or may not have been addressed, but I'v
been looking for answers for a while and can't find any. Frankly, it'
driving me crazy. So, here's the question.
I created separate macros to initialize values for three cells i
Excel. The reason I did this is because they each refer to cells i
relation to themselves, so one macro won't work. Now I am trying t
select a row (or the first cell in the row) to have one macro activat
all three. However, the macro only references the row I recorded th
macro on, not any other row I may select. I've tried four or fiv
different ways to edit the macro (both after recording it or simpl
starting cold). Nothing seems to work. Can anyone help me t
reference cells in a macro, based on the starting row or cell?

ex. Row 12 is selected. A12 should execute Macro1, B12 Macro2, an
C12 Macro3
OR
Cell A5 is selected. A5 is Macro1, B5 Macro2, and C5 Macro3

Either way is fine with me, either selecting the first of three cell
or the entire row. Thanks for any help you can give me.

New excel, old programmer...

--
GatheringShado
-----------------------------------------------------------------------
GatheringShadow's Profile: http://www.excelforum.com/member.php...fo&userid=1552
View this thread: http://www.excelforum.com/showthread.php?threadid=27096

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cell selection in a macro


you could try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Column = 1 And ActiveCell.Row <= 30 Then
Macro1
ElseIf ActiveCell.Column = 2 And ActiveCell.Row <= 30 Then
Macro2
ElseIf ActiveCell.Column = 3 And ActiveCell.Row <= 30 Then
Macro3

End If
End Sub

where macro1,2 or 3 is the name of the macro you call on you can chang
the Activecell.Row to be the last row in your data.

Hope this helps

Simo

--
Simon Lloy
-----------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...nfo&userid=670
View this thread: http://www.excelforum.com/showthread.php?threadid=27096

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Cell selection in a macro

Put this in the code module for the worksheet (not a general module where
macros 1-3 are)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A:A"), Target) Is Nothing Then
macro1
macro2
macro3
Else
Exit Sub
End If
End Sub

This should detect when any cell is selected in column A and run the macros
in succession.

Mike F
"GatheringShadow" wrote in
message ...

This is a question that may or may not have been addressed, but I've
been looking for answers for a while and can't find any. Frankly, it's
driving me crazy. So, here's the question.
I created separate macros to initialize values for three cells in
Excel. The reason I did this is because they each refer to cells in
relation to themselves, so one macro won't work. Now I am trying to
select a row (or the first cell in the row) to have one macro activate
all three. However, the macro only references the row I recorded the
macro on, not any other row I may select. I've tried four or five
different ways to edit the macro (both after recording it or simply
starting cold). Nothing seems to work. Can anyone help me to
reference cells in a macro, based on the starting row or cell?

ex. Row 12 is selected. A12 should execute Macro1, B12 Macro2, and
C12 Macro3
OR
Cell A5 is selected. A5 is Macro1, B5 Macro2, and C5 Macro3

Either way is fine with me, either selecting the first of three cells
or the entire row. Thanks for any help you can give me.

New excel, old programmer....


--
GatheringShadow
------------------------------------------------------------------------
GatheringShadow's Profile:

http://www.excelforum.com/member.php...o&userid=15529
View this thread: http://www.excelforum.com/showthread...hreadid=270964



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
Line selection from a cell script through a VBA macro CamiIRE Setting up and Configuration of Excel 2 April 11th 06 04:28 PM
Macro - Dynamic cell selection Chris Excel Discussion (Misc queries) 1 January 11th 06 01:48 PM
Macro for cell selection starting with Last Cell Valerie Excel Worksheet Functions 4 December 9th 05 08:25 PM
excel: activitaing a macro upon selection of a cell arunjoshi[_16_] Excel Programming 1 May 31st 04 12:52 PM
Selection.Replace doesn't update the cell value in macro! Nasser Hosseini Excel Programming 1 February 26th 04 07:41 PM


All times are GMT +1. The time now is 10:14 PM.

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"