Replacing < and > with numbers using If Then loop

VAPALIPOT

New Member
Joined
Jan 18, 2010
Messages
14
I want to scan a column of numbers that occasionally contain some values that have either "< 0.000" or a "> 10" listed. When I find them, I need to write a slightly different string set to an adjacent column. I also need to write an integer to a third column as a FLAG. So when I find the "< 0.000", I need to replace it with a "<" and the cell value I have stored elsewhere (e.g., "N31"), then write a 5 to an adjacent cell on the same row. A similar activity occurs with the "> 10.4" except there is a multiplication that occurs to create the inserted value after the ">". Finally, an integer 2 is inserted into the same column as the 5.

Code:
Sub TEST1()
' This sub designed to screen for occurrences of "<" and ">" in Columns "6" and "8" respectively & insert appropriate answers in Column "8" and then insert corresponding flags in Col "9"
    Dim patternLESS As String
    Dim patternMORE As String
    Dim j As Integer    'j = row
    Dim I As Integer    'i = column
    Dim DilFactor As Long

    patternLESS = "<"
    patternMORE = ">"

    For j = 77 To 86
        If Cells(j, 6) = patternLESS Then
            Cells(j, 8) = "<" & "N31"
            Cells(j, 9) = 5
        End If
    Next j

    For j = 77 To 86
        If Cells(j, 6) = patternMORE Then
            DilFactor = Cell(j, 7).Value * Cell("N22").Value
            Cells(j, 8) = ">" & "DilFactor"
            Cells(j, 9) = 2
        End If
    Next j
End Sub

I tried to run this code but it came back with 'undefined function' at the DilFactor line where I was trying to multiply two cell values. My apologies as I couldn't find the section that indicated that I had code to upload on the Post New Thread section.

Thanks for your help.
 
Last edited by a moderator:
You are welcome!

Glad you got it working!
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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