1

I encounter the following error within my Excel macro when I tried to execute it : Compilation Error : Function or Variable expected.

Here is my code :

            'On split le libellé afin de récupérer la chaîne de caractère source1 à rechercher dans la colonne B du PSR
            TabSrcDoubleEntree = Split(PtoutPar(j).Nom, "/")
            ' on récupère la ligne du PSR (colonne B) dans laquelle la chaîne source 1 (=TabSrcDoubleEntree(0)) est renseignée
            Set sheet = Workbooks(PFile).Sheets(ParMap(j).Parametrage.SrcFeuille)
            **With sheet.Activate**
                Set celluleRowRange = .Range("B", .Range("B").End(xlUp))
                Set celluleFind = celluleRowRange.Find(TabSrcDoubleEntree(0), LookIn:=xlValues, lookat:=xlWhole)
                celluleRowFind = celluleFind.Row
            End With
            'on initialise la ligne à partir de laquelle on fait la recherche à "c.Row"
            ThisWorkbook.Sheets(PFeuilleDest).Cells(iDest, ParMap(j).Parametrage.DestCol).Value = Workbooks(PFile).Sheets(ParMap(j).Parametrage.SrcFeuille).Cells(celluleFind.Row + ParMap(j).Parametrage.SrcPremiereLigne, ParMap(j).Parametrage.SrcCol).Value

=> Does anyone know why the instruction sheet.Activate is not correct ??

THanks a lot Simon

1 Answers1

0

The With "this" statement is used to perform the following block from the context of "this". In your case you are performing the block from the context of the Activate function, rather than the sheet itself, which is throwing a compile error. I would recommend changing it to the following

' Perform the following from the context of sheet    
With sheet
    .Activate
    Set celluleRowRange = .Range("B", .Range("B").End(xlUp))
    ' ...
End With
Tim Hall
  • 1,475
  • 14
  • 16