This is shooting in the dark because I do not know what 'does not work' means.
But if I were to guess, I'd say that it is working. If you can load a sketch where its a fixed value, and you see the resistance as expected, then it seems its a problem with your delay - meaning that it's too fast. With the delay(100), its essentially changing the resistance every 100ms. Can your meter pick that up well ? Can your eyes pick that up well ?
Change your delay(100) to delay(10000) which would give you a 10 second window to check the resistance. If you want more, try a higher ms value for your delay function.
If you provide more information, we can maybe give you a bit more insight as to why something is 'not working'.
edit from additional information
Perhaps the SPI mode is incorrect.
From the datasheet
Drive CS low to load the data at DIN(U/D) synchronously into the shift register on each SCLK(INC) rising edge.
It seems that SPI.setDataMode(SPI_MODE2) is incorrect. Because MODE 2 is base of the clock is high, and data is captured on the falling edge.
Change your SPI.setDataMode(SPI_MODE2) to SPI.setDataMode(SPI_MODE3) and see if you have better results.