XL.Sheet.SetCellFormat
----------------------

Sets cell's format.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [XL](component_XL.md) | [3.5](newinversion35.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "XL.Sheet.SetCellFormat"; BookRef; SheetIndex; Row; Column; Format ) 

**MBS**( **"XL.Sheet.SetCellFormat";** /\* Sets cell's format. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$SheetIndex**; /\* The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1.e.g. 0 \*/   
**$Row**; /\* The row for the cell. First row has index 0. \*/   
**$Column**; /\* The column for the cell. First column has index 0. \*/   
**$Format**) /\* The format for the cell. This is index from 0 to XL.GetFormatCount-1 in the book's list of formats.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| BookRef | The reference number for the workbook. | $ref |
| SheetIndex | The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1. | 0 |
| Row | The row for the cell. First row has index 0. | $row |
| Column | The column for the cell. First column has index 0. | $column |
| Format | The format for the cell. This is index from 0 to XL.GetFormatCount-1 in the book's list of formats. | 0 |

### Result

Returns OK or error.

### Description

Sets cell's format.  
### Examples

Apply a new format to a column:

 #create new format   
Set Variable \[$format ; Value:MBS ( "[XL.Book.AddFormat](XLBookAddFormat.md)"; $BookRef )\]  
Set Variable \[$r ; Value:MBS ( "[XL.Format.SetNumFormat](XLFormatSetNumFormat.md)"; $BookRef ; $format ; 7)\]  
\#set as format for column   
Set Variable \[$r ; Value:MBS ( "[XL.Sheet.SetColumn](XLSheetSetColumn.md)"; $BookRef ; 0; 6; 6; 50 ; $format ; 0 )\]  
\#loop over all rows   
Set Variable \[$lastRow ; Value:MBS ( "[XL.Sheet.GetLastRow](XLSheetGetLastRow.md)"; $BookRef ; $sheet )\]  
Set Variable \[$row ; Value:1\]  
Loop  
 Set Variable \[$r ; Value:MBS ( "XL.Sheet.SetCellFormat"; $BookRef ; $sheet ; $row ; 6; $format )\]  
 #next  
 Set Variable \[$row ; Value:$row + 1\]  
 Exit Loop If \[$row &gt; $lastRow \]  
End Loop  
Make a cell bold:

 Set Variable \[ $sheet ; Value: 0 \]  
\#   
\# create a bold font   
Set Variable \[ $boldFont ; Value: MBS ( "[XL.Book.AddFont](XLBookAddFont.md)"; $bookRef ) \]  
Set Variable \[ $r ; Value: MBS ( "[XL.Font.SetBold](XLFontSetBold.md)"; $bookRef ; $boldFont ; 1) \]  
\#   
\# create a bold format   
Set Variable \[ $boldFormat ; Value: MBS ( "[XL.Book.AddFormat](XLBookAddFormat.md)"; $bookRef ) \]  
Set Variable \[ $r ; Value: MBS ( "[XL.Format.SetFont](XLFormatSetFont.md)"; $bookRef ; $boldFormat ; $boldFont ) \]  
\#   
\# now apply the new format to a cell   
Set Variable \[ $r ; Value: MBS ( "XL.Sheet.SetCellFormat"; $bookRef ; $sheet ; 3; 1; $boldFormat ) \]  
### See also

- [XL.Book.SheetCount](XLBookSheetCount.md)
- [XL.Font.SetBold](XLFontSetBold.md)
- [XL.Format.SetFont](XLFormatSetFont.md)
- [XL.Sheet.CellWriteMatrix](XLSheetCellWriteMatrix.md)
- [XL.Sheet.ColFormat](XLSheetColFormat.md)
- [XL.Sheet.GetCellError](XLSheetGetCellError.md)
- [XL.Sheet.GetCellFormat](XLSheetGetCellFormat.md)
- [XL.Sheet.GetCellFormats](XLSheetGetCellFormats.md)
- [XL.Sheet.GetLastRow](XLSheetGetLastRow.md)
- [XL.Sheet.SetColumn](XLSheetSetColumn.md)

### Release notes

- **Version 8.0**
    - Added [XL.Sheet.CellReadBooleans](http://www.mbsplugins.eu/XLSheetCellReadBooleans.shtml), [XL.Sheet.CellReadComments](http://www.mbsplugins.eu/XLSheetCellReadComments.shtml), [XL.Sheet.CellReadDates](http://www.mbsplugins.eu/XLSheetCellReadDates.shtml), [XL.Sheet.CellReadFormulas](http://www.mbsplugins.eu/XLSheetCellReadFormulas.shtml), [XL.Sheet.CellReadNumbers](http://www.mbsplugins.eu/XLSheetCellReadNumbers.shtml), [XL.Sheet.CellReadTexts](http://www.mbsplugins.eu/XLSheetCellReadTexts.shtml), [XL.Sheet.CellWriteBlanks](http://www.mbsplugins.eu/XLSheetCellWriteBlanks.shtml), [XL.Sheet.CellWriteBooleans](http://www.mbsplugins.eu/XLSheetCellWriteBooleans.shtml), [XL.Sheet.CellWriteComments](http://www.mbsplugins.eu/XLSheetCellWriteComments.shtml), [XL.Sheet.CellWriteDates](http://www.mbsplugins.eu/XLSheetCellWriteDates.shtml), [XL.Sheet.CellWriteFormulas](http://www.mbsplugins.eu/XLSheetCellWriteFormulas.shtml), [XL.Sheet.CellWriteNumbers](http://www.mbsplugins.eu/XLSheetCellWriteNumbers.shtml), [XL.Sheet.CellWriteTexts](http://www.mbsplugins.eu/XLSheetCellWriteTexts.shtml), [XL.Sheet.GetCellErrors](http://www.mbsplugins.eu/XLSheetGetCellErrors.shtml), [XL.Sheet.GetCellFormats](http://www.mbsplugins.eu/XLSheetGetCellFormats.shtml), [XL.Sheet.RemoveComments](http://www.mbsplugins.eu/XLSheetRemoveComments.shtml) and [XL.Sheet.SetCellFormats](http://www.mbsplugins.eu/XLSheetSetCellFormats.shtml).

This function checks for a license.

Created 18th August 2014 , last changed 7th October 2025

  
[XL.Sheet.SetBorder](XLSheetSetBorder.md) - [XL.Sheet.SetCellFormats](XLSheetSetCellFormats.md)

[HTML Version](XLSheetSetCellFormat.shtml)