ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   stupid round question (https://www.excelbanter.com/excel-programming/369621-stupid-round-question.html)

Sergei D

stupid round question
 
Hi! I have been using round function a lot in worksheets. But now I am
writing a macro and want to select a column and then round all of the numbers
in it. For some reason, no metter what I do, I can not seem to figure out how
to do that... Any suggestions?
--
Sergei D

somethinglikeant

stupid round question
 
To Format a column to 2 d.p

:=======================
Sub RoundColumn()
Columns("A:A").NumberFormat = "#,##0.00"
End Sub
:=======================

To round each value in a selection to 2 d p

:=======================
Sub RoundColumnValue()

Dim cl As Range

For Each cl In Selection
cl.Value = Application.WorksheetFunction.Round(cl.Value, 2)
Next cl

End Sub

:=====================

http://www.excel-ant.co.uk


Ardus Petus

stupid round question
 
cells(1,1).value = Round (cells(1,1).value)

HTH
--
AP

"Sergei D" a écrit dans le message de
news: ...
Hi! I have been using round function a lot in worksheets. But now I am
writing a macro and want to select a column and then round all of the
numbers
in it. For some reason, no metter what I do, I can not seem to figure out
how
to do that... Any suggestions?
--
Sergei D




Sergei D

stupid round question
 
this is great... but how can I appy it to the whole column?
--
Sergei D


"Ardus Petus" wrote:

cells(1,1).value = Round (cells(1,1).value)

HTH
--
AP

"Sergei D" a écrit dans le message de
news: ...
Hi! I have been using round function a lot in worksheets. But now I am
writing a macro and want to select a column and then round all of the
numbers
in it. For some reason, no metter what I do, I can not seem to figure out
how
to do that... Any suggestions?
--
Sergei D





Sergei D

stupid round question
 
this seems logical and should work. But.. i get: "object variable or with
object variable not set" error message.
--
Sergei D


"somethinglikeant" wrote:

To Format a column to 2 d.p

:=======================
Sub RoundColumn()
Columns("A:A").NumberFormat = "#,##0.00"
End Sub
:=======================

To round each value in a selection to 2 d p

:=======================
Sub RoundColumnValue()

Dim cl As Range

For Each cl In Selection
cl.Value = Application.WorksheetFunction.Round(cl.Value, 2)
Next cl

End Sub

:=====================

http://www.excel-ant.co.uk



Sergei D

stupid round question
 
actually.. I got it working. Thanks.
cl does not stand for cell???.. because when I changed to cl it began to
work...again. thanks
--
Sergei D


"somethinglikeant" wrote:

To Format a column to 2 d.p

:=======================
Sub RoundColumn()
Columns("A:A").NumberFormat = "#,##0.00"
End Sub
:=======================

To round each value in a selection to 2 d p

:=======================
Sub RoundColumnValue()

Dim cl As Range

For Each cl In Selection
cl.Value = Application.WorksheetFunction.Round(cl.Value, 2)
Next cl

End Sub

:=====================

http://www.excel-ant.co.uk




All times are GMT +1. The time now is 10:02 AM.

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