Wednesday 8 April 2015

VBA trick with for loop and interior color

Copy-paste the below code to sheet1 coding under project explorer and run the macro by assigning it to button click .


Sub Button1_Click()

Range("a1:U21").Interior.Color = vbBlack


Cells.ClearContents

  For j = 20 To 1 Step -1

    For i = 1 To 20 - j

    Cells(j, i).ClearFormats

    Cells(j, i).ClearContents

    Cells(j, i).Columns.AutoFit

    Cells(j, i).Interior.ColorIndex = j

  
    Cells(j, i).Value = "**************"

    Next i

    Next j

    Cells.Columns.AutoFit

End Sub

 

No comments:

Post a Comment