且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用VBA将单元格值从一个单元格复制到另一个单元格

更新时间:2023-02-04 19:45:56

复制格式:

Range("F10").Select
Selection.Copy
Range("I10:J10").Select ' note that we select the whole merged cell
Selection.PasteSpecial Paste:=xlPasteFormats

复制格式会破坏合并的单元格,因此您可以使用它来将单元格重新组合在一起

copying the formatting will break the merged cells, so you can use this to put the cell back together

Range("I10:J10").Select
Selection.Merge

要复制单元格值,而不复制任何其他内容(并且不使用复制/粘贴),您可以直接寻址单元格

To copy a cell value, without copying anything else (and not using copy/paste), you can address the cells directly

Range("I10").Value = Range("F10").Value

其他属性(字体、颜色、etc )也可以通过以相同方式直接寻址范围对象属性来复制

other properties (font, color, etc ) can also be copied by addressing the range object properties directly in the same way