Formatting a newly inserted row.

Microsoft Excel 2010 - complete product...
October 1, 2012 at 12:08:54
Specs: Windows 7
Hello,

A user on this forum helped me to write a macro in order to insert a new row with a specific formula in it. Because the row above where I am inserting the new row is formatted differently than how I would like the newly inserted row to be formated I need to add to the macro to format the row and have no idea how to do this. The code I have this far to insert the row is:

Sub OTHER_ROW_01()
'Insert row above named range
  Range("OTHER_01").EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
'Put formula in new row
  Range("E" & Range("OTHER_01").Row - 1).FormulaR1C1 = "=RC[-2]*RC[-1]"
'Format new row
Range("E" & Range("OTHER_01").Row - 1).FormulaR1C1 = "=RC[-2]*RC[-1]"
End Sub

When I record a macro of me just giving the proper attributes to my new row this is what the code looks like:

Sub Macro1()

    Range("A41:F41").Select
    Selection.Font.Bold = False
    With Selection.Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("B41:D41").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 10092543
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("F41").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 10092543
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub


See More: Formatting a newly inserted row.

Report •


#1
October 1, 2012 at 15:38:56
Is there another row in the spreadsheet formatted the same way as the newly inserted row?

If so, why not just have the macro copy the formatting from that row?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •
Related Solutions


Ask Question