Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50163

[SOLVED] Changing a code to worksheet function

$
0
0
:):)Dear Experts, I have created a code & I would like to change it to worksheet function. Currently it has a button to run the code but I want to modify this. It should run on its own every time value in cell A1 (Number) changes and get rid of the button. Please find below the code and any guidance to change/ improve is welcome.
Best Regards/VKS
Code:

Sub HeaderFormat_ForAP()
'
'
    Range("a2:XFD2").Select’ This can be changed to clear row 2 but I couldn’t get it right
    Selection.ClearContents
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "2013"
    Range("B2").Select
    ActiveCell.Resize(, Range("a1") - 1).Select
    With Selection
        .FormulaR1C1 = "=R[0]C[-1]+1"
            .Value = .Value
                .HorizontalAlignment = xlRight
                    .Style = "Comma"
                        .NumberFormat = "0_ ;-0 "
                End With
                Range("A1").Select
   
End Sub


Viewing all articles
Browse latest Browse all 50163

Trending Articles