#!usr/perl/bin use strict; use warnings; my $Formula = "=MAX(B499:AR499)"; #desired: "=MAX(B500:AR500)" my ($formula_begin, $therest) = split /\({1}/, $Formula; # ESCAPE the open paren my ($cell1, $cell2) = split /:/, $Formula; my ($cell1a, $cell1b) = split /\(/, $cell1; my ($cell2a, $closeparen) = split /\)/,$cell2; # One way to get rid of the trailing ')' so we can increment the number, later. print "First cell referenced: $cell1b, second cell referenced: $cell2a\n\n"; $cell1b =~ /([A-Z]+)(\d+)/; my $cell1balpha = $1; my $cell1bdigits = $2; $cell2a =~ /([A-Z]+)(\d+)/; my $cell2aalpha = $1; my $cell2adigits = $2; ++$cell1bdigits; ++$cell2adigits; print "AFTER INCREMENT, first cell referenced: $cell1balpha" . $cell1bdigits . "; second cell referenced: $cell2aalpha" ."$cell2adigits\n\n"; print "\tRefs adjusted formula: $formula_begin" . "($cell1balpha" . $cell1bdigits. ":$cell2aalpha" ."$cell2adigits" . ")\n";