When you select the area in XL, classically, you start from the cell at the top left and end at the bottom right. What happens if you do from bottom right to top left, or from bottom left to top right (the goal is to finish the selection at the top)?
Do you know Lisp (language used for Autocad macros at the beginning)
I added a few comments
(SETQ txt (CLIP-GET)); We retrieve the contents of the clipboard
(SETQ YGAP 100); we initialize
(IF (NOT txt) (QUIT "*Cancel*")) ; We check that the content is not empty (SETQ txt (STRREPLACE txt "\t" " ")); replace the column separator (tab) with a space (SETQ txt (STRREPLACE txt "\n" ")(")) ; the change of line is replaced by a )( (SETQ txt (STRREPLACE txt "\r" "")) ; I don't know what return is (in what is retrieved from the clipboard (SETQ txt(STRREPLACE txt "," ".")) ; we replace the , by .
(SETQ txt (STRCAT "((" (SUBSTR txt 1 (1- (STRLEN txt))) "))")) ; we complete to have one (at the beginning and one) at the end
(SETQ txtlist (READ txt)); the string of characters is converted into a form that can be understood by the language
The "list" system, characteristic of Lisp, means that by adding the pairs (), we directly retrieve the pairs "s" of coordinates, which are themselves lists.
CAR and CADR allows the sub-parts of the coordinate pair to be extracted. FYI we can combine the a and d to extract a particular element from a list with a lot of elements (typically the result of the "list" command applied to an element or a family of elements (in which case we have a list of lists, and it can go a long way).
I don't know why there is a test on ymax, nor what basep and YGAP are for