调整宏以复制单元格背景/填充颜色

问题描述 投票:0回答:1

我现在正在使用下面的 Marco,如果可能的话,我想添加复制单元格背景颜色的功能。

Sub test()
  Dim sh1 As Worksheet, sh As Worksheet
  Dim f As Range
  Dim j As Long, lr1 As Long, lr As Long

  
  Set sh1 = Sheets("Labor Mapping")
  
  With Sheets("Labor Mapping")
    .Rows(2 & ":" & .Rows.Count).Clear
    End With
  
  For Each sh In Sheets
    If sh.Name <> sh1.Name Then
        lr1 = sh1.Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row + 1
      
      lr = sh.Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
      
      For j = 1 To sh.Cells(1, Columns.Count).End(1).Column
        Set f = sh1.Rows(1).Find(sh.Cells(1, j), , xlValues, xlWhole, , , False)
        
        If Not f Is Nothing Then
          sh1.Cells(lr1, f.Column).Resize(lr).Value = sh.Cells(2, j).Resize(lr).Value
    
        End If
      Next
    End If
  Next
  
  Sheets("Labor Mapping").Columns("G").Delete

End Sub
excel vba
1个回答
0
投票

不确定这是否是您正在寻找的,我认为可能有更短的方法来表达它,但我正在尝试使用 range 属性:

sh1.Range(sh1.Cells(lr1, f.Column),sh1.Cells(lr1, f.Column)).Interior.Color = sh.Range(sh.Cells(2, j),sh.Cells(2, j)).Interior.Color

© www.soinside.com 2019 - 2024. All rights reserved.