Batch saving a custom field to multiple users via controller
For such large amounts of operations it's best to use a Job. You should only make sure to batch your results and don't fetch every user separately.

use Craft;
use craft\base\Element;
use craft\db\QueryAbortedException;
use craft\elements\User;
use craft\helpers\App;
use craft\queue\BaseJob;
use yii\base\Exception;

class ResaveUsers extends BaseJob
{
    // Properties
    // =========================================================================

    /**
     * @var int[] The user Ids
     */
    public $userIds;

    /**
     * @var string the reference number
     */
    public $refNumber;

    // Public Methods
    // =========================================================================

    /**
     * execute
     *
     * @param \craft\queue\QueueInterface|\yii\queue\Queue $queue
     *
     * @throws \Throwable
     * @throws \craft\errors\ElementNotFoundException
     * @throws \yii\base\Exception
     *
     * @author Robin Schambach
     * @since  07.05.2019
     */
    public function execute($queue)
    {
        $query = User::find()-&gt;id($this-&gt;userIds);

        $totalElements = $query-&gt;count();
        $currentElement = 0;

        $elements = \Craft::$app-&gt;getElements();

        try {
            $i = 0;
            foreach ($query-&gt;each() as $user) {
                $i ++;
                $this-&gt;setProgress($queue, $currentElement++ / $totalElements);

                $tableValue   = $user-&gt;getFieldValue( 'aktionsRefNumber' );
                $tableValue[] = [
                    'col0' =&gt; $this-&gt;refNumber . '-' . $i,
                ];
                $user-&gt;setFieldValue( 'aktionsRefNumber', $tableValue );

                /** @var Element $element */
                $user-&gt;setScenario(Element::SCENARIO_ESSENTIALS);
                if (!$elements-&gt;saveElement($user)) {
                    throw new Exception('Couldn’t save element ' . $user-&gt;id . ' (' . get_class($user) . ') due to validation errors.');
                }
            }
        } catch (QueryAbortedException $e) {
            // Fail silently
        }
    }

    // Protected Methods
    // =========================================================================

    /**
     * @inheritdoc
     */
    protected function defaultDescription(): string
    {
        return Craft::t('app', 'Resaving {class} elements', [
            'class' =&gt; App::humanizeClass(User::class)
        ]);
    }
}


You can start your job with 

Craft::$app-&gt;getQueue()-&gt;push(new ResaveUsers([
     'userIds' =&gt; [1,2,4,5,6],
     'refNumber' =&gt; 'foobar'
]));