开发者

How to copy values in merged cells from one worksheet to another?

I have a sheet called "main" that takes values from another file's sheet called "data".

With "ActiveSheet.copy" (in the "main" file) it copies the sheet but with the cells' links.

Is there any way to copy just the values of the sheet?

Second, my "main" sheet has some merged cells so even if I manually copy & paste the sheets by selecting a range it can't be cop开发者_如何学Cied due to the merged cells.


Check out the options you get with PasteSpecial:

  • Values: this will not copy links and just values only
  • All except borders: this will retain merged cell formatting

Example - suppose you want to copy sheet1 to sheet 2 where sheet 1 has merged cells

  • In Sheet1 press CTRL + A to select all and then CTRL + C to copy
  • In Sheet2 select cell A1
  • Now right click and select Paste Special...
  • In the dialog box select All except borders...

Updated - VBA

Sub CopyWithMergedCells()
    ActiveSheet.Cells.Copy //select all cells on sheet1 and copy
    Worksheets("Sheet2").Select 
    Cells.Select //select all cells on sheet2
    Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone,    SkipBlanks:=False, Transpose:=False //paste with formats preserved
End Sub

Paste:=xlPasteAllExceptBorders is the key bit. You need to change this if you want to just copy values (and not links)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜