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....
 
That might look like this

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"
        [COLOR=royalblue]Set rng = Worksheets("[B]Sheet4[/B]").Range("A5")
[/COLOR]        rng.Formula = "=IV9"
    End Select
End Sub

This is liable to get convoluted rather quickly.
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi

... or use another output range:


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rng1 As Range, rng2 As Range
 
    Set rng1 = Worksheets("Sheet3").Range("A5")
    Set rng2 = Worksheets("Sheet4").Range("E3")
 
    Select Case Target.Address
        Case Is = "$G$9"
            rng1.Formula = "=AD1"
        Case Is = "$G$10"
            rng1.Formula = "=AD2"
        Case Is = "$G$11"
            rng2.Formula = "=IV9"
    End Select
End Sub
 
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

That might look like this

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"
        [COLOR=royalblue]Set rng = Worksheets("[B]Sheet4[/B]").Range("A5")
[/COLOR]        rng.Formula = "=IV9"
    End Select
End Sub

Thank you that will save lots of my time
Set rng2 = Worksheets("Sheet4").Range("E3")
[/CODE]

This is liable to get convoluted rather quickly.
Thanks again that was quick :)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
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