+ Reply to Thread
Results 1 to 8 of 8

stupid round question

Hybrid View

  1. #1
    Sergei D
    Guest

    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

  2. #2
    somethinglikeant
    Guest

    Re: 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


  3. #3
    Ardus Petus
    Guest

    Re: stupid round question

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

    HTH
    --
    AP

    "Sergei D" <SergeiD@discussions.microsoft.com> a écrit dans le message de
    news: B3E5E617-3DAB-4F1A-84CD-E3AB4E3113DB@microsoft.com...
    > 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




  4. #4
    somethinglikeant
    Guest

    Re: 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


  5. #5
    Sergei D
    Guest

    Re: 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
    >
    >


  6. #6
    Sergei D
    Guest

    Re: 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
    >
    >


  7. #7
    Ardus Petus
    Guest

    Re: stupid round question

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

    HTH
    --
    AP

    "Sergei D" <SergeiD@discussions.microsoft.com> a écrit dans le message de
    news: B3E5E617-3DAB-4F1A-84CD-E3AB4E3113DB@microsoft.com...
    > 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




  8. #8
    Sergei D
    Guest

    Re: 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" <SergeiD@discussions.microsoft.com> a écrit dans le message de
    > news: B3E5E617-3DAB-4F1A-84CD-E3AB4E3113DB@microsoft.com...
    > > 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

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1