Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

IfAnd macro, but only for first line. Need to add a loop for all lines

I created a if and, but need to add a loop. Cannot get a loop to work.

Sub IfAnd()

If Range("j2") = "9-99-9998" And Range("f2") <> 2 Then
Range("k2").Value = "Indirect"
Else
If Range("j2") = "9-99-9998" And Range("F2") = 2 Then
Range("k2").Value = "IndirectOT"
Else
If Range("j2") <> "9-99-9998" And Range("F2") <> 2 Then
Range("k2").Value = "Direct"
Else
If Range("j2") <> "9-99-9998" And Range("F2") = 2 Then
Range("k2").Value = "DirectOT"
End If
End If
End If
End If

End Sub

created an array, but did not work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Option Explicit

Sub IfAnd()
    Dim r As Long, s As String
    For r = 2 To 3
        If Cells(r, "J") = "9-99-9998" Then
            s = "Indirect"
        Else
            s = "Direct"
        End If
        
        If Cells(r, "F") = 2 Then
            s = s & "OT"
        End If
        Cells(r, "K") = s
   Next
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading