Wednesday, April 8, 2015

Format excels and clear the old format and data


4/8/15:

objExcel.Cells(1, 1).Value = "Name"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Interior.ColorIndex = 30
objExcel.Cells(1, 1).Font.ColorIndex = 2

'List excel colors

For i = 1 to 56
    objExcel.Cells(i, 1).Value = i
    objExcel.Cells(i, 1).Interior.ColorIndex = i
Next

' Clear and ClearContent

Range("X").Cells.Clear   ' this will clear the content along with background color
Range("X").Cells.ClearContents ' clears only content


Note: Remem­ber “.Clear” will clear the every­thing from the cell right from cell data to cell for­mat­ting, bor­ders etc.

If you just want to clear the con­tent or data of the cells with­out effect­ing the for­mat and bor­der of the cell use “.ClearCon­tents

mainworkBook.Sheets(“MyFirstMacro”).Range(“C6”).ClearContents
 

No comments:

Post a Comment