If you are on a particular worksheet and you want to programmatically set the active cell to be a cell in another sheet, you may think you could do that by using the following code...

((Globals.ThisAddIn.Application.ActiveWorkbook.Sheets[
    "SheetName"] as Worksheet).Cells[iRow, iCol] 
        as Range).Select();

But you'd be wrong. The above code generates the ultra-helpful "The select method on the Range object failed!". To make a cell on a non-current worksheet active you must first make the non-current worksheet active and then select the cell, like so...

//GS - Make the required sheet active
Worksheet ws = 
    Globals.ThisAddIn.Application.ActiveWorkbook.Sheets[
        fd.Sheetname] as Worksheet;

ws.Activate();

//GS - Select the required range in the now active sheet
(ws.Cells[fd.Row, fd.Column] as Range).Select();
 
Technorati Tags: , ,