ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Can macros output to a cell selected prior to running it? (https://www.excelbanter.com/excel-worksheet-functions/13782-can-macros-output-cell-selected-prior-running.html)

winnie

Can macros output to a cell selected prior to running it?
 
I need to know if it is possible to run a macro from a cel that you specify
right before runing the macro (i.e. a variable cell rather than the same
constant cell which is usually specified within the macro).

Steve

Hi Winnie

Store the required address in a spare worksheet.
Check your target address against your required address with If().

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Dim tAddr
Dim reqAddr

reqAddr = UCase(Worksheets("Sheet2").Range("A1").Value)
tAddr = Target.Address

If tAddr = reqAddr Then MsgBox "it works"

End Sub


HTH
Steve

"winnie" wrote in message
...
I need to know if it is possible to run a macro from a cel that you specify
right before runing the macro (i.e. a variable cell rather than the same
constant cell which is usually specified within the macro).




Dan Knight

Winnie;
This may be overly simplified, but if by "a cell that you specify", you're
thinking the activecell. Then in the macro simply refer to the Activecell
property.

Sub ()
prev code....

msgbox Activecell.address

rest of code...
end sub

"winnie" wrote:

I need to know if it is possible to run a macro from a cel that you specify
right before runing the macro (i.e. a variable cell rather than the same
constant cell which is usually specified within the macro).


Myrna Larson

If you mean the macro returns a value, change the code so it puts that value
in the active cell, i.e.

'calculate some value, x, here
ActiveCell.Value = X

On Thu, 17 Feb 2005 13:23:02 -0800, winnie
wrote:

I need to know if it is possible to run a macro from a cel that you specify
right before runing the macro (i.e. a variable cell rather than the same
constant cell which is usually specified within the macro).




All times are GMT +1. The time now is 06:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com