I have used the code above and it does exactly what I need but it nearly caught me out, so I figured I'd post even though the thread's been dead for a while.
I created three tables in my document and gave each a caption, 'Figure 1' to 'Figure 3'. In my text I made cross references to 'Figures 1' and '3' but not to 'Figure 2'. Crucially, my cross references to 'Figure 3' preceded the actual table and its caption.
I then deleted just the caption 'Figure 2' from my second table, and nothing changed. In other words, the caption 'Figure 3' stayed as 'Figure 3' and was not changed to 'Figure 2'.
I expected to be able to run the code and have it change any references to 'Figure 3' from 'Figure 3' to 'Figure 2', but this didn't happen. In retrospect, it is obvious because the code works sequentially through the document checking both cross references and captions. When it gets to the references that precede 'Figure 3', it checks that they are valid and of course they are at that point. It is only later, when the code gets to the third table in the document that it changes caption 'Figure 3' to 'Figure 2'.
Thus you end up with a document that contains references to a caption 'Figure 3' that no longer exists.
The simple solution is to run the code twice...