2015-10-14 114 views
0

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

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 
+0

进入宏录制和手动更改行的属性。然后获取这些知识并根据需要将代码插入到VBA中。 –

回答

1

你明白了没有,你只需要后 Rows(lRow).EntireRow.Insert

一条线,那就是Range("A" & lRow & ":H" & lRow).Interior.Color = 5287936

+0

我知道我一定要接近,但是我几乎很尴尬。感谢斯科特 –