# IF/Nested IF Statement help!

L

#### Legacy 313594

##### Guest
Excel & VBA Folks,

I'm fairly new to VBA, but have been working hard to learn & help my company. I need help consolidating my code though, it's long & continually tests IF statements. The below code runs through about 1500 rows trying to match trade breaks to two seperate spreadsheets depending on whether
Code:
``cells(i,"H) = "CORPLD or Cells(i,"H")="MUNI"``
containing up to 3000 trades, using several IF/ Vlookups. If it returns a match, it moves to the next i (row).

Can anyone help with consolidating my code? Do I have the right idea with the NESTED IF's or is it an overkill?

Code:
``````For i = 2 To N
If Cells(i, "H") = "FIX" Or Cells(i, "H") = "LCV" Then
GoTo Arsenal2:
End If

If Cells(i, "H") = "MUNI" Then
GoTo London:
End If

If Cells(i, "H") = "CORPLD" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "CORPLD" And Cells(i, "U") = "Non-Trade Related" Then
End If

London:
If Cells(i, "H") = "MUNI" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then
End If

Arsenal2:
Next i``````

#### mrmmickle1

##### Well-known Member
What exactly are you trying to accomplish?:

If these are all the same condition:
Code:
``````[COLOR=#ff0000]If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then[/COLOR]
End If

[COLOR=#ff0000]If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then[/COLOR]
End If

[COLOR=#ff0000]If Cells(i, "H") = "MUNI" And Cells(i, "U") = "Non-Trade Related" Then[/COLOR]
End If``````
You can consolidate like this:
Code:
``````[COLOR=#0000ff]If[/COLOR] Cells(i, "H") = "MUNI" [COLOR=#0000ff]And[/COLOR] Cells(i, "U") = "Non-Trade Related"[COLOR=#0000ff] Then[/COLOR]
[COLOR=#0000ff]End If[/COLOR]``````

No need to repeat the same condition over and over again Hope this helps! Keep up the good work.

Last edited: