I have a script that can ping a list of computers and change their background color depending after the result it gets.
My problem is, that it blocks the entire exce
You can't do too much about this unfortunately since VBA runs in a single thread.
You can however introduce a degree of responsiveness by putting
VBA.DoEvents()
in various places in your code, ideally in the tight loops. In your case, put them just after the lines containing For
. This pauses the VBA and flushes the event queue which will have the effect of making Excel responsive.
(Toggling the screen updating is a bad idea since you might leave things in a bad state if the function terminates unexpectedly. I'd remove the lines that do that if I were you.)
While strictly speaking you cannot make Excel to behave as you need, there is a trick to work around it. The solution is to create another Excel instance. Then you can run the macro in one of the instances and work independently in the other one. You can open another Excel instance from the Run prompt (press Windows + R) and then type Excel /x, then Enter
Excel can calculate "asynchronously". Call sPing
as a function.
I'm not sure why your range is A1:N50. I assume one of the columns is the IP address, which I will assume as A. So your formula in column M will look like =sPing(A1)
.
As for the color coding, you can use conditional formatting.