Find and Replace

MyersEPS

New Member
Joined
Nov 2, 2018
Messages
14
Hello,

I am trying to find and replace 2 place decimals numbers in a column with 3 place decimals using vba. The problem is that some of the numbers are over an hour (1.16 should be 1.167) in time. I tired using wildcards, but it seems to put the wildcard character in with the number. Any help would be appreciated.

Thanks
 
Code is now replacing the values in the original cell UNLESS the cell contains a formula

Code:
Sub ValueReplace()
    Dim Hrs As Integer, M As Integer, Valu As Double, Decml As Double, calcDecml As Double, cel As Range, Rng As Range
    With ActiveSheet
        Set Rng = .Range("D2", .Range("D" & Rows.Count).End(xlUp))
    End With
    
    For Each cel In Rng
        [COLOR=#ff0000]If Not cel.HasFormula Then[/COLOR]
            Valu = cel.Value
            If Valu <> 0 Then
                Hrs = Fix(Valu):   Decml = Valu - Hrs
                For M = 0 To 59
                    calcDecml = Round(M / 60, 3)
                    If Abs(Decml) <= calcDecml Then
                        If Valu < 0 Then calcDecml = -calcDecml
                            [COLOR=#000080]cel = Hrs + calcDecml[/COLOR]
                            Exit For
                    End If
                Next M
            End If
        [COLOR=#ff0000]End If[/COLOR]
    Next cel
End Sub
 
Last edited:
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top