ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Formatting Cells (https://www.excelbanter.com/excel-programming/376382-formatting-cells.html)

RSteph

Formatting Cells
 
I'm running through a list of cells with dollar values. Some are even dollars
some are not. (ie. 10, 10.45, etc.)

I don't want to worry about adding a dollar sign, and there's no negative
values. I would like to format the cells though so that there's 2 decimal
places no matter what.

How would I best go about doing this? Here's the loop I'm running:

Dim lastRow As Long 'Used to hold the value of last row on the sheet.
Dim i As Integer 'Used to incriment For Loop.

lastRow = Cells(Rows.Count, "H").End(xlUp).Row 'Get the last row on the page.

For i = 2 To lastRow 'Start at 2 to ignore heard line.
If Cells(i, "H").Value < "" And Cells(i, "H").Value < 0 Then
Cells(i, "H").Value = Cells(i, "H").Value / Cells(i, "G").Value
End If
Next i 'Incriment counter and reloop

While I'm at it, does anyone know of a link, or perhaps able to suggest a
book for me to look at, that lists all the various properties, etc. for
objects in VBA (such as Cells, Rows, Range, etc.) Sometimes options come up
and sometimes they don't in the editor.

RSteph

Formatting Cells
 
Actually I think I got it with:

Cells(i, "H").NumberFormat = "0.00"


All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com