Consulting

Results 1 to 5 of 5

Thread: Roundup values in specific Range using vba

  1. #1
    VBAX Regular
    Joined
    Jun 2018
    Posts
    26
    Location

    Roundup values in specific Range using vba

    Hello everybody

    How to roundup values in specific Range??
    I have a range (AL7:AN131)
    if the user entered value like 2.3 in the target range
    the vba round it up to 3

    thank you.

  2. #2
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    277
    Location
    Sub RoundUpInRange()
        Dim rng         As Range
    
    
        For Each rng In Range("AL7:AN131")
            If Not IsError(rng.Value) Then
                If IsNumeric(rng.Value) Then
                    rng.Value = Application.WorksheetFunction.RoundUp(rng.Value, 0)
                End If
            End If
        Next rng
    End Sub
    Artik

  3. #3
    VBAX Regular
    Joined
    Jun 2018
    Posts
    26
    Location
    thank you it is working but it fills empty cell with zero in the target range
    just I wnat to focus on cell when entering the value in the target range only

  4. #4
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    277
    Location
    It is enough to add one more condition
    Sub RoundUpInRange_1()
        Dim rng         As Range
    
    
        For Each rng In Range("AL7:AN131")
            If Not IsError(rng.Value) Then
                If Not IsEmpty(rng.Value) Then
                    If IsNumeric(rng.Value) Then
                        rng.Value = Application.WorksheetFunction.RoundUp(rng.Value, 0)
                    End If
                End If
            End If
        Next rng
    End Sub
    Artik

  5. #5
    VBAX Regular
    Joined
    Jun 2018
    Posts
    26
    Location
    Perfect

    Thank You

Posting Permissions

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