热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

复制行内容和格式(到另一个工作表)-Copyarowscontentsandformatting(toanothersheet)

WhatdoIwantistocopyanentirerowscontentsandformattingtoanothersheet.我想要的是将整行的内容和格式复制

What do I want is to copy an entire row's contents and formatting to another sheet.

我想要的是将整行的内容和格式复制到另一张表。

At the moment I've had to settle for setting the old cells contents to the new cells contents and in doing so it only copies the contents and not the formatting. (my cells have different colours that need to be carried across)

目前我不得不解决将旧单元格内容设置为新单元格内容的问题,这样做只会复制内容而不是格式化内容。 (我的细胞有不同的颜色,需要携带)

At the moment I have the following: (this works fine for cells in the same sheet)

目前我有以下内容:(这适用于同一张表格中的单元格)

Range(Cells(45, 2), Cells(45, 3)).Copy Range(Cells(50, 2), Cells(50, 3))

However, I'm trying to do it from one sheet to another. (Copy from sheet 'Front_Page' to 'vg'). I tried using the following, obviously it doesn't work, but can someone please tell me what am I doing wrong?

但是,我正试图从一张纸到另一张纸。 (从工作表'Front_Page'复制到'vg')。我尝试使用以下,显然它不起作用,但有人可以请告诉我我做错了什么?

Range.Worksheet("Front_Page").Range(Cells(45, 2), Cells(45, 3)).Copy Worksheet("vg").Range(Cells(50, 2), Cells(50, 3))

2 个解决方案

#1


1  

Looks like you try to copy cells from "Front_Pages" to "vg" since you use "cells" inside "range"

看起来你试图将单元格从“Front_Pages”复制到“vg”,因为你在“范围”中使用“单元格”

Range (cells ...).

范围(单元格......)。

If so, you can simply change the cell format as excel general range; try this code :

如果是这样,您只需将单元格格式更改为excel一般范围;试试这段代码:

Sheets("vg").Range("B5") = Sheets("Front_Pages").Range("B4")
Sheets("vg").Range("C5") = Sheets("Front_Pages").Range("C4")

#2


0  

Cells refers to cells of active sheet. Thus you get the error: vg is not the active sheet. Specifying cells of another sheet as parameters to Range object always leads to an error. This will work:

细胞是指活性片的细胞。因此,您会收到错误:vg不是活动工作表。将另一个工作表的单元格指定为Range对象的参数始终会导致错误。这将有效:

Worksheets("Front_Page").Range(Worksheets("Front_Page").Cells(45, 2), Worksheets("Front_Page").Cells(45, 3)).Copy Worksheets("vg").Range(Worksheets("vg").Cells(50, 2), Worksheets("vg").Cells(50, 3))

However, it can be optimized to just:

但是,它可以优化为:

Worksheets("Front_Page").Range("B45:C45").Copy Worksheets("vg").Range("B50:C50")

Also, notice that Worksheet("vg") doesn't work, it should be replaced with Worksheets("vg") else it will cause error too.

另外,请注意Worksheet(“vg”)不起作用,应该用Worksheets(“vg”)替换,否则它也会导致错误。

To copy entire row, use:

要复制整行,请使用:

Worksheets("Front_Page").Rows("45:45").Copy Worksheets("vg").Rows("50:50")

推荐阅读
author-avatar
陈雅洁惠真慧瑋
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有