2

i am trying to paste something in a specific Excel Cell, but sometimes its paste the data somewhere else.

 workSheet = ExcelApp.Worksheets[2] as Excel._Worksheet;
             Grd_Dep_In.SelectAll();
            Grd_Dep_In.Copy();
            Excel.Range DepIn = cellsRange.get_Range("a2");
            DepIn.Select();
            workSheet.Paste();

Sometimes its pastes in A2, sometimes not.

So i want to check if a2 is the selected cell.

before i start to paste. My Code copys in 8 worksheets and generates pivot tables. and sometimes it mess up and copys somewhere else in the excel worksheet.

So what I need:

if (activeCell= A2)
{
paste

}

But i dont know how to detertimate the active excel cell.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Daniel Lenzendorf
  • 97
  • 1
  • 2
  • 11
  • Could any of these be the answer? http://stackoverflow.com/questions/4080741/get-user-selected-range, http://stackoverflow.com/questions/3230937/getting-the-selected-cells-range-from-a-different-worksheet-in-excel?rq=1, http://stackoverflow.com/questions/3686787/excel-vba-get-range-of-user-selected-range-by-mouse?rq=1 – chiccodoro Jun 04 '14 at 07:41
  • This poster - http://stackoverflow.com/questions/18968856/vba-paste-range - uses `Cell.Activate()`, and the answer simply uses `Cells(1, 1).Paste` – chiccodoro Jun 04 '14 at 07:42

1 Answers1

3

Try this:

Excel.Range rng = (Excel.Range) this.Application.ActiveCell;
int row = rng.Row;
int column = rng.Column;

if (row == 1 && column == 1)
{
  // paste
}
Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92