More problems with trimming for range of values

klarowe

Active Member
Joined
Mar 28, 2011
Messages
389
Right now I have this code that was provided to me by one of you guys (thanks!)
Code:
            Set rng = Range(nm.Name)
            On Error Resume Next
            For Each Dn In rng
                If rng.Value <> "" Then
                    Dmin = Val(Trim(Replace(Split(Dn.Offset(, 2), "-")(0), """", "")))
                    Dmax = Val(Trim(Replace(Split(Dn.Offset(, 2), "-")(1), """", "")))
                    If InStr(Dn, "-") Then
                        temp1 = Val(Trim(Replace(Split(Dn, "-")(0), """", "")))
                        temp2 = Val(Trim(Replace(Split(Dn, "-")(0), """", "")))
                        Dn.Interior.ColorIndex = IIf(temp1 >= Dmin And temp1 <= Dmax And temp2 >= Dmin And temp2 <= Dmax, 0, 3)
                    Else
                        temp = Replace(Dn, """", "")
                        Dn.Interior.ColorIndex = IIf(temp >= Dmin And temp <= Dmax, 0, 3)
                    End If
                Else: Dn.Interior.ColorIndex = 0
                End If
                If rng.Offset(, 2).Value = "" Then Dn.Interior.ColorIndex = 0
                If rng.Value = "NA" Or rng.Value = "N/A" Or rng.Value = "na" Or rng.Value = "n/a" Or rng.Value = "Na" Or rng.Value = "N/a" _
                        Or rng.Value = "nA" Or rng.Value = "n/A" Then Dn.Interior.ColorIndex = 0
            Next Dn

It works great if the user enters the value as ie 1.00" - 2.00" however we have some users that like to enter it as ie 1.00" / 2.00". How can I modify the above code to allow both entries to work? No matter what I try, I can't get it.
Thanks

Kenny
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Figured it out... not sure if its the "right" wya but it works.. haha
Code:
                If rng.Value <> "" Then
                    Dmin = Val(Trim(Replace(Split(Dn.Offset(, 2), "-")(0), """", "")))
                    Emin = Val(Trim(Replace(Split(Dn.Offset(, 2), "/")(0), """", "")))
                    Dmax = Val(Trim(Replace(Split(Dn.Offset(, 2), "-")(1), """", "")))
                    Emax = Val(Trim(Replace(Split(Dn.Offset(, 2), "/")(1), """", "")))
                    If InStr(Dn, "-") Then
                        temp1 = Val(Trim(Replace(Split(Dn, "-")(0), """", "")))
                        temp2 = Val(Trim(Replace(Split(Dn, "-")(0), """", "")))
                        
                        Dn.Interior.ColorIndex = IIf(temp1 >= Dmin And temp1 <= Dmax And temp2 >= Dmin And temp2 <= Dmax, 0, 3)
                        Dn.Interior.ColorIndex = IIf(temp1 >= Dmin And temp1 <= Emax And temp2 >= Emin And temp2 <= Dmax, 0, 3)
                    Else
                        temp = Replace(Dn, """", "")
                        Dn.Interior.ColorIndex = IIf(temp >= Dmin And temp <= Dmax, 0, 3)
                    End If
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,014
Latest member
Chris258

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