Running a VBA macro when a condition is met

I create a table to teach my numerical skills.

Now I use VBA macros to create a new problem once the current one has been resolved correctly. To do this, I still need to press the button on the worksheet, which is worth the time and annoying.

Is there a way I can execute a macro when a certain condition is met?

eg:

if A1 = "correct!" then <run macro> else <do nothing> 

Also, let me know if you are interested in a spreadsheet, I would be happy to share it with you guys.

better pieter

+4
source share
2 answers

Add this as code for your worksheet:

 Private Sub Worksheet_Change(ByVal Target As Range) If (Range("A1") = "correct!") Then ''# do your stuff here End If End Sub 

Worksheet_Change is called whenever something changes. It looks like A1 being calculated, you cannot check the Target in this case, but check the cell value.

+5
source

= IF (A1 = "Vikram", 9.8)

You will write = IF (A1 = "Vikram", 9.8). In plain English, it means that if the value of cell A1 is Vikram, then the value in which these formulas are located is 9, otherwise it is 8

0
source

Source: https://habr.com/ru/post/1303441/


All Articles