将多个单元格颜色从一个工作表复制到另一个工作表 [英] Copy multiple cell colours from one worksheet to another

查看:127
本文介绍了将多个单元格颜色从一个工作表复制到另一个工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建VBA代码时,我是一个新手.我想自动将单元格颜色从一个工作表复制到另一个工作表.

I am a novice when it comes to building VBA code. I want to automatically copy cell colours from one worksheet to another.

我在下面提供了一些图像,以帮助解释我希望实现的目标:

I have provided some images below to help explain what I am hoping to achieve:

工作表1-3月18日:

Worksheet 1 - Mar 18:

工作表7-网站1:

Worksheet 7 - Site 1:

查看工作表1-3月18日,我想将单元格颜色从第3行(从B3到X3)复制到工作表7-站点1的B列(从B3到B23).我还有其他工作表,从4月18日到12月18日,从站点2到站点6,我想执行类似的操作.

Looking at Worksheet 1 - Mar 18, I want to copy the cell colours from row 3 (B3 to X3) to Worksheet 7 - site 1 Column B (B3 to B23). I also have additional worksheets, Apr 18 to Dec 18 and Site 2 to Site 6 where I would like to perform similar actions.

最终结果将把月份工作表中的信息汇总到站点工作表中.

The end result will roll up the information from the month worksheets into the site worksheets.

推荐答案

这是一个简单的例程,该例程演示了如何根据第二张纸上的单元格颜色对一张纸上的单元格进行着色.完全理解此代码的工作原理之后,您应该可以对其进行修改以适用于您的情况.如果您有任何问题,请告诉我.

Here's a simple routine that demonstrates how cells on one sheet can be colored based on the color of cells in a second sheet. After you thoroughly understand how this code works, you should be able to modify it to apply to your situation. Let me know if you have questions.

Sub colorCells()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim r1 As Range, r2 As Range, numToColor As Integer, i As Integer
Set sh1 = Worksheets("1")
Set sh2 = Worksheets("2")
Set r1 = sh1.Range("B3")
Set r2 = sh2.Range("B3")
numToColor = 10
For i = 1 To numToColor
  r2.Offset(0, i).Interior.Color = r1.Offset(0, i).Interior.Color
Next i
End Sub

这篇关于将多个单元格颜色从一个工作表复制到另一个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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