Can macros output to a cell selected prior to running it?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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).
 
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;
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
 
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
 

Ask a Question

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.

Ask a Question

Back
Top