# How to evaluate an input cell automatically after evaluating the previous one

Is there any way to automatically evaluate an input cell after evaluating the previous one without the need to press ENTER?

• Out of curiosity - is there a reason why you wouldn't want to put them into the same cell? – Jonie Aug 7 '13 at 5:16
• @Jonie Because I want the next cell be evaluated only if certain conditions are met. I also want to separate the outputs. – M6299 Aug 7 '13 at 5:20

One way to acheive this is:

a = 1 + 2
If[a == 3, SelectionMove[EvaluationNotebook[], Next, Cell]];
SelectionEvaluate[EvaluationNotebook[]];


Other way is by adding CellTag to our "conditional" cell. Use Crtl+J on that cell or use menu: Cell > Cell Tags > Add/Remove... to add tag, here I used "only if".

And then:

a = 1 + 2;
If[a == 3,
NotebookLocate["only if"];
SelectionEvaluate[EvaluationNotebook[]]
]


This seems to be more bulletproof.

• Thanks. Your solutions are exactly what I needed. – M6299 Aug 7 '13 at 6:13
• @M6299 You are welcome :) I'm glad you find it useful. – Kuba Aug 7 '13 at 6:14