8
$\begingroup$

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

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

1 Answer 1

9
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Thanks. Your solutions are exactly what I needed. $\endgroup$
    – M6299
    Commented Aug 7, 2013 at 6:13
  • $\begingroup$ @M6299 You are welcome :) I'm glad you find it useful. $\endgroup$
    – Kuba
    Commented Aug 7, 2013 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.