filling in 1,0 for the first 10 rows in excel vba

时间:2015-07-28 17:06:14

标签: vba excel-vba excel

in the column AR I have to fill in 1 from AR3 to AR13 and 0 from AR14 to the last row. is there any way to automate it in vba?

2 个答案:

答案 0 :(得分:0)

Simplest and fastest solution, without a loop

LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "AR").End(xlUp).Row
Range("AR3:AR13")=1
Range("AR14:AR" & LastRow )=0

答案 1 :(得分:0)

    Dim lRow As Long
    Dim ws As Excel.Worksheet

    Set ws = Application.ActiveSheet
    lRow = 3
    Do While lRow <= ws.UsedRange.Rows.count
        if lrow <= 13 then
            ws.Range("AR" & lrow).Value = 1
        Else
            ws.Range("AR" & lrow).Value = 0
        End if

        lRow = lRow + 1
        ws.Range("AR" & lRow).Activate
     Loop