Login   /   Register

Format a Range of Cells

Rate this article
     0 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 5
Loading ... Loading ...
April 1st, 2008 by daniva

Demonstration script that adds data to four different cells in a spreadsheet, then uses the Range object to format multiple cells at the same time.

Set excel = CreateObject( "Excel.Application" )
With excel
   .Visible = True
   .Workbooks.Add
   .Cells( 1, 1 ).Value = "Name"
   .Cells( 1, 1 ).Font.Bold = True
   .Cells( 1, 1 ).Interior.ColorIndex = 30
   .Cells( 1, 1 ).Font.ColorIndex = 2
   .Cells( 2, 1 ).Value = "Test value 1"
   .Cells( 3, 1 ).Value = "Test value 2"
   .Cells( 4, 1 ).Value = "Tets value 3"
   .Cells( 5, 1 ).Value = "Test value 4"
End With
Set range = excel.Range( "A1","A5" )
range.Font.Size = 14
 
Set range = excel.Range( "A2","A5" )
range.Interior.ColorIndex = 36
 
Set range = excel.ActiveCell.EntireColumn
range.AutoFit()    

Posted in MS-Excel

Leave a Reply

You must be logged in to post a comment.

This article was viewed 364 times