Try insert an EndIf an the end and see whether that helps ?
Please notice : if it helps, your code most probably won’t do what you want, but at least you then know it is about an Endif missing somewhere.
It could also be about a Next or Wend missing. … Difficult to troubleshoot …