【问题标题】:excel vba insert row and change colorexcel vba插入行并更改颜色
【发布时间】:2016-01-13 02:30:19
【问题描述】:

我需要更改由下面的宏代码插入的行(或特定行中的单元格 A 到 H)的颜色。扫描 Col H 的 if 语句是需要进行颜色更改的地方。

Sub SolidWorks()

Application.ScreenUpdating = False

Range("A100000").End(xlUp).Activate
Range("N1") = ActiveCell.Row

For lrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row To 1 Step -1
If Cells(lrow, "B") = 0 Then
            Rows(lrow).EntireRow.Delete
End If
Next lrow

For lrow = Cells(Cells.Rows.Count, "H").End(xlUp).Row To 1 Step -1
    If Cells(lrow, "H") <> Cells(lrow - IIf(lrow = 1, 0, 1), "H") Then
            Rows(lrow).EntireRow.Insert  '<---- insert green row, instead of just a blank row
'.Color = 5287936
'                With Selection.Interior
'                .Pattern = xlSolid
'                .PatternColorIndex = xlAutomatic
'                .Color = 5287936
'                .TintAndShade = 0
'                .PatternTintAndShade = 0
'                End With
    End If
Next lrow

For lrow = Cells(Cells.Rows.Count, "G").End(xlUp).Row To 1 Step -1
    If Cells(lrow, "G") <> Cells(lrow - IIf(lrow = 1, 0, 1), "G") Then
            Rows(lrow).EntireRow.Insert
    End If
Next lrow

Range("A1").Select

Application.ScreenUpdating = True

End Sub

【问题讨论】:

  • 转到宏记录器并手动更改行的属性。然后根据需要将这些知识插入到您的 VBA 中。

标签: vba excel colors format


【解决方案1】:

你已经找到了,你只需要在后面一行 Rows(lRow).EntireRow.Insert

那就是Range("A" &amp; lRow &amp; ":H" &amp; lRow).Interior.Color = 5287936

【讨论】:

  • 我知道我一定很亲近,但我是如此亲近几乎令人尴尬。谢谢斯科特
猜你喜欢
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-12
  • 2017-11-19
  • 2019-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多