获取选定的Excel单元格 [英] Get selected excel cell

查看:80
本文介绍了获取选定的Excel单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将某些内容粘贴到特定的Excel单元格中,但有时会将数据粘贴到其他地方.

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();

有时将其粘贴在A2中,有时不粘贴.

Sometimes its pastes in A2, sometimes not.

所以我想检查a2是否为选定的单元格.

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

在我开始粘贴之前.我的代码将复制到8个工作表中并生成数据透视表.有时会弄乱并复制到Excel工作表中的其他地方.

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.

所以我需要什么

if (activeCell= A2)
{
paste

}

但是我不知道如何确定活跃的Excel单元格.

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

推荐答案

尝试一下:

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

if (row == 1 && column == 1)
{
  // paste
}

这篇关于获取选定的Excel单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆