Phil Meier
7/17/2007 6:40:00 AM
Todd Burch wrote:
> addr = "$G$28:$I$28" # merged cell range
> addr =~ /:\$/ # isolates the "I$28" into $'
> back = $' # puts "I$28" into a variable
> back =~ /\$/ # "I" and "28" go into $` and $' respectively
> puts "row=#{$'}, Col=#{$`}"; # -> Row=28, Col=I - Bingo!
>
> I then simply let EXCEL convert I to 9. (or AA to 27, etc...)
>
> Any insight for improvement is appreciated - for both the regex and my
> usage of EXCEL in this situation.
>
> Thanks, Todd
>
You can have this in one RegEx:
addr = "$G$28:$I$28"
addr =~ /:\$*([A-Z])+\$*(.*)$/
puts "row=#{$2}, col=#{$1}" # -> row=28, col=I
An addr = "G28:I28" would also be accepted by the RegEx.