用最新数据覆盖现有工作表 [英] overwrite existing worksheet with latest data

查看:67
本文介绍了用最新数据覆盖现有工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有一个工作簿,其中包含几个相互引用的工作表和公式。令人感兴趣的是"数据"。工作表。我想清除此工作表的全部内容,并将其他工作表中的内容复制到空白的"数据"中。
工作表。

  I have a workbook with several worksheets and formulas referencing each other. Of interest is the "data" worksheet. I want to clear the entire contents of only this worksheet and copy contents from another worksheet to the blank "data" worksheet.

如果我使用workheet.copy函数,它会创建一个新工作表并将其复制到我不需要的工作表中。我还尝试删除现有的工作表并添加一个具有相同名称的新工作表,但抛弃了其他工作表中的所有公式。

If I use the worksheet.copy function, it creates a new worksheet and copies into it which I do not want. I have also tried deleting the existing worksheet and adding a new one with the same name but throws off all the formulas in other worksheets.

请帮助!

//清除工作表

((范围)targetWorkSheet.Range [" A1",Type.Missing])。清除() ;

((Range)targetWorkSheet.Range["A1", Type.Missing]).Clear();

工作表targetWorkSheet = targetWb.Worksheets [" Data"];

Worksheet targetWorkSheet = targetWb.Worksheets["Data"];

 工作表newDataSheet = sourceWb.Sheets [1];

  newDataSheet  .Name =" Data";

 Worksheet newDataSheet = sourceWb.Sheets[1];
 newDataSheet .Name = "Data";

//将数据从newDataSheet复制到targetWorkSheet - ?????

// Copy data from newDataSheet to targetWorkSheet - ?????

推荐答案

你好,

如果要覆盖现有工作表,只需删除工作表即可。然后使用worksheet.copy方法创建新工作表并将名称指定为"数据"。

If you want to overwrite the existing worksheet, you could simply delete the sheet. Then use worksheet.copy method to create a new sheet and specify the name into "Data".

如果您不想删除工作表,可以使用Range.Copy方法。

If you do not want to delete the sheet, you could use Range.Copy method.

问候,

Celeste


这篇关于用最新数据覆盖现有工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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