Link to home
Create AccountLog in
Avatar of KFFrench
KFFrench

asked on

Can't call method "Range" on an undefined value

I can't seem to get past this point in my code. For some reason Perl is unable to read some cells of the data in an Excel spreadsheet and returns the error: Can't call method "Range" on an undefined value. Here is the code I'm using:

my $Sheet = $Book->Worksheets ("Data");
my @CF = ($ID, $SO, $LI, $QT, $CR->Date(DATE_SHORTDATE), $CR->Time,
          $MOD->Date(DATE_SHORTDATE), $MOD->Time);
sub GetCF($){
    my ($tgtRows)= @_;
        my $Sheet;
            Return ($Sheet->Range("A".$tgtRows)->{'Value'},
                    $Sheet->Range("L".$tgtRows)->{'Value'},
                    $Sheet->Range("M".$tgtRows)->{'Value'},
                    $Sheet->Range("S".$tgtRows)->{'Value'},
                    $Sheet->Range("V".$tgtRows)->{'Value'},
                    $Sheet->Range("Z".$tgtRows)->{'Value'});  
ASKER CERTIFIED SOLUTION
Avatar of wlfs
wlfs

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of KFFrench
KFFrench

ASKER

Ok, so I changed my $Sheet to Our $Sheet in both places and it now says that the subroutine is undefined. I have ialso included the remaing parts of scripts where I try to create the $tmphash.

our $Sheet = $Book->Worksheets ("Data");
my @CF = ($ID, $SO, $LI, $QT, $CR->Date(DATE_SHORTDATE), $CR->Time,
          $MOD->Date(DATE_SHORTDATE), $MOD->Time);
sub GetCF($){
    my ($tgtRows)= @_;
        our $Sheet;
            Return ($Sheet->Range("A".$tgtRows)->{'Value'},
                    $Sheet->Range("L".$tgtRows)->{'Value'},
                    $Sheet->Range("M".$tgtRows)->{'Value'},
                    $Sheet->Range("S".$tgtRows)->{'Value'},
                    $Sheet->Range("V".$tgtRows)->{'Value'},
                    $Sheet->Range("Z".$tgtRows)->{'Value'});

@CF=GetCF($Rows);

while ($Sheet->Range("A". ++$Rows)->{'Value'}){
    my @CF = GetCF($Rows);
    if (!exists $tmphash {$CF[1]}->{$CF[2]}){
        print $CF [1][2];
    }
}
Sorry but I don't know the Excel modul at all. So I'm afraid I can't help you any further.
If you don't bother about the points, just post the new problem in a new question. If you do bother, ask in
https://www.experts-exchange.com/Community_Support/
to undo the accept and reopen the question. Other experts won't read this and provide answers as long as the question is marked as accepted.