Results 1 to 9 of 9

Set decimal places by cell value

Threaded View

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Set decimal places by cell value

    I am converting values from SAE to Metric and wish to retain the decimal places of the SAE value before converting. My code below converts nicely but doesnt maintain decimal places.

    Option Explicit
    Dim Sh1Range   'Sh1Range
    Dim Sh1LastRow    'Sht1LastRow
    Dim Sh1Cell    'Sh1Cell
    Dim X
    Dim iTimeStart As Double, iTimeEnd As Double, Y As Double
    
    Sub Metric()
        With Sheets("Sheet1")
            'Loop thru Column E
            Sh1LastRow = .Cells(Rows.Count, "E").End(xlUp).Row
            Set Sh1Range = .Range("E1:J" & Sh1LastRow)
        End With
    
        For Each Sh1Cell In Sh1Range
            Sh1Cell.Activate
            If IsNumeric(Sh1Cell.Value) Then
                'get decimal place of cell value and set for converted value
                X = 25.4 * Sh1Cell.Value
                Sh1Cell.Value = X
            End If
        Next Sh1Cell
        Columns("E:J").Select
        Selection.Columns.AutoFit
        Range("E1").Select
    End Sub
    Any hints, tips and or examples are appreciated.
    Last edited by Rick_Stanich; 06-23-2009 at 09:53 AM.
    Regards

    Rick
    Win10, Office 365

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