If Cell A1 is Active than Type Some Formula in Cell A5

  • Thread starter Thread starter Legacy 185509
  • Start date Start date
L

Legacy 185509

Guest
Hi
Please help me do this
I have over 100 cells if any one is active at one time, it will write different formula in cell A5
if A1 is active it will write may be =2+2
if A3 is active it will write in A5 =S3

and so on....
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Something like this, I believe

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rng As Range
    Set rng = Range("A5")
    Select Case Target.Address
    Case Is = "$A$1"
        rng.Formula = "=2+2"
    Case Is = "$A$2"
        rng.Formula = "=S3"
    End Select
End Sub

Right click on the tab and 'View Code' to get to the
Worksheet_SelectionChange(ByVal Target As Range) procedure
 
Upvote 0
Something like this, I believe

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rng As Range
    Set rng = Range("A5")
    Select Case Target.Address
    Case Is = "$A$1"
        rng.Formula = "=2+2"
    Case Is = "$A$2"
        rng.Formula = "=S3"
    End Select
End Sub

Right click on the tab and 'View Code' to get to the
Worksheet_SelectionChange(ByVal Target As Range) procedure


Thanks alot man you are a
tumblr_lq3zim5RKh1qiqv7w.jpg
 
Upvote 0
any reason why this work on my home computer & not at my work computer
both are same version, both are office 2007
please help
 
Upvote 0
No reason that I am aware of.
This is straight Excel, not even anything version-dependent that I know.


You don't have any code that says...
If Home = True then Works = True Else Works = False
do you?
 
Upvote 0
No reason that I am aware of.
This is straight Excel, not even anything version-dependent that I know.


You don't have any code that says...
If Home = True then Works = True Else Works = False
do you?
no, I tired your code yesterday from home, & it worked on my personal laptop, but I m trying same code on my work computer it doesn't work
any reason why?
here is screenshot of my VB code page
24fxu0z.jpg
 
Upvote 0
Check events & macros are enabled on your work PC.

Paste the code below into your VBA Immediate Window then press enter
Code:
Debug.print Application.EnableEvents

If you get
Code:
TRUE
then Events aren't your issue but if you get
Code:
FALSE
they are.

You can turn them on again through

Code:
Application.EnableEvents = TRUE
but it could be that they are being turned off by some other code...

M
 
Upvote 0
Hey I need help again
I modified the code

here is how it looks

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rng As Range
    Set rng = Worksheets("Sheet3").Range("A5")
    Select Case Target.Address
    Case Is = "$G$9"
        rng.Formula = "=AD1"
    Case Is = "$G$10"
        rng.Formula = "=AD2"
    Case Is = "$G$11"
     [B]   rng.Formula = "=IV9"[/B]
    End Select
End Sub
I wanna make it like if they click G11 it will write on sheet4 instead of sheet3
it is working fine for G9 & G10, it writes to Sheet3 A5.
thanks
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,718
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top