VBA activate Sheet in Excel

McM_

New Member
Joined
Oct 23, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hello
I know this is a beginner problem, but is there anyone who can help me with the information below?
How to activate VBA that launches a formula from the Sheet, and that formula to run C3:C100, without the need to launch with F5?
In the end, I managed to display the date under certain conditions, without needing to activate it with F5.
I can't find how to activate the formulas without F5.
Please excuse the technical terms.
Thank you !
VBA Code:
Sub Macrocomandã5()    Range("C2:C8").Select    ActiveCell.FormulaR1C1 = "=IF(RC[-2]>0,(RC[-2]+RC[-1]),"""")"    Range("C2:C8").Select    Range("C3").Activate    End SubPrivate Sub worksheet_Change(ByVal Target As Range)Dim ws As WorksheetIf Target.Column = 8 ThenRange("I" & Target.Row) = NowEnd IfIf Target.Column = 14 ThenRange("M2:M" & Target.Row) = Range("L2")End IfEnd Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    42 KB · Views: 9

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You have posted two macros:

VBA Code:
Sub Macrocomand5()
    Range("C2:C8").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-2]>0,(RC[-2]+RC[-1]),"""")"
    Range("C2:C8").Select
    Range("C3").Activate
End Sub

VBA Code:
Private Sub worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    If Target.Column = 8 Then
        Range("I" & Target.Row) = Now
    End If
    If Target.Column = 14 Then
        Range("M2:M" & Target.Row) = Range("L2")
    End If
End Sub


Can you explain what you are trying to make them do?
 
Upvote 0
True, I posted 2 macros. What I'm looking for is to transpose formulas in VBA to be activated without F5. What helps me is to receive a code that automatically activates the formulas in the sheet when a condition is met. In the first macro I took a simple example of the formula and I need the code to activate the formula in the sheet, after which I will apply the example in the future to all my projects. I am not interested in the formula but in the way of its activation.
If I was not understood, I will come back with explanations. At the same time, today I redid the post in which I also attached the table.
 
Upvote 0
In Macros two it is like an example. The formulas are automatically activated when the conditions are met. That's what I want in the first macro as well
 
Upvote 0
I am also attaching the table

VBA.xlsm
ABCDEFGHIJKLMNO
1Example 1Example 2Example 3
2it only works with F5 activationit works without activating F5it works without activating F5write here
3123it only works with F5 activationabc27.10.2023 10:14testtestyyt
434didn't workcda27.10.2023 10:14testgghfh
559didn't workbac27.10.2023 10:14testghgh
64didn't workabd27.10.2023 10:15testyuyu
728.10.2023 05:39
8
9
10
11
12
13
14
15
16 
17 t
18 
19 
20 
21 
22 
Foaie1
Cell Formulas
RangeFormula
C3,C16:C22C3=IF(A3>0,(A3+B3),"")
 
Upvote 0
I don't understand what you mean when you say you use F5 to "activate" the formula. On my copy of Excel, pressing F5 brings up the "Go To" dialog.

1698522737290.png
 
Upvote 0
Hello!
This code only runs by clicking on Run Macros (F5). But I want more.
I want the formulas to run when a condition is met. Colleagues who work on the table will not have access to click on Run Macros.
I have attached the picture
 

Attachments

  • prtsc.JPG
    prtsc.JPG
    30.4 KB · Views: 6
Upvote 0
What you are doing doesn't really make sense since you are populating the same or at least overlapping range of rows each time.
But see if this gives you any ideas.

Rich (BB code):
Private Sub worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    
    Application.EnableEvents = False
    If Target.Column = 8 Then
        Range("I" & Target.Row) = Now
    End If
    
    If Target.Column = 14 Then
        Range("M2:M" & Target.Row) = Range("L2")
    End If

    If Target.Column = 1 Or Target.Column = 2 Then
        Range("C2:C" & Target.Row).FormulaR1C1 = "=IF(RC[-2]>0,(RC[-2]+RC[-1]),"""")"
        
        ' Not sure why you would want these 2 lines but I kept them in
        Range("C2:C" & Target.Row).Select
        Range("C3").Activate
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
It is my fault that I complicated the table, to give an example of how I want the ending to be.
I redo the table with what I need.
At this moment, if B3 is a number, automatically minus B3-A3.
If B4 fulfills the condition (isnumber), it does not decrease B4-A4 and so on every row.....
ThanK for your time!

VBA Code:
Sub Macrocomandã4()

    Range("C3").Select
    ActiveCell.FormulaR1C1 = "=IF(ISNUMBER(RC[-1]),RC[-1]-RC[-2],"""")"
    Range("D3").Select
End Sub



VBA.xlsm
ABCDE
2
3121
434didn't work
559didn't work
6didn't work
7
8 
9 
10
11 
12
13
14
Foaie1
Cell Formulas
RangeFormula
C3,D11,C8:C9C3=IF(ISNUMBER(B3),B3-A3,"")
 
Upvote 0
Is the actual question here maybe being lost in a language translation and is
How to trigger a macro from cells containing a formula ?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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