excel vba 插入行并改变颜色
excel vba insert row and change color
我需要更改由下面的宏代码插入的行(或特定行中的单元格 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
你已经搞定了,后面只需要一行
Rows(lRow).EntireRow.Insert
也就是Range("A" & lRow & ":H" & lRow).Interior.Color = 5287936
我需要更改由下面的宏代码插入的行(或特定行中的单元格 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
你已经搞定了,后面只需要一行
Rows(lRow).EntireRow.Insert
也就是Range("A" & lRow & ":H" & lRow).Interior.Color = 5287936