Finding Matches in a Range / Formatting Call to Sub The code below cycles through a number of columns/pairs of columns looking for a match and doing something with it. I have this structure in three different subs with the difference being what I have labeled ' Unique Code '. My two questions are is there an obvious way to combine the two softwareCol loops and how could I structure this better to isolate the identical code.

Sub filterFile()
    ActiveWorkbook.Worksheets("Current File").ListObjects("SoftwareTable").DataBodyRange.Rows.Hidden = True
    Dim currentFile As Worksheet: Set currentFile = ActiveWorkbook.Sheets("Current File")
    Dim cell As Object
    Dim softwareCol As Integer
    Dim targetSoftware As String
    targetSoftware = UserForm1.TextBox1.Value &amp; " " &amp; UserForm1.TextBox2.Value
    With currentFile
        For softwareCol = 0 To 10
            For Each cell In .Range("J2:J" &amp; lastRow(currentFile)).Offset(0, softwareCol * 2)

                ' Unique Code '
                If targetSoftware = cell.Value &amp; " " &amp; cell.Offset(0, 1).Value Then
                    cell.Rows.Hidden = False
                End If

            Next
        Next softwareCol
        For softwareCol = 0 To 5
            If Not (softwareCol = 2 Or softwareCol = 4) Then
                For Each cell In .Range("AF2:AF" &amp; lastRow(currentFile)).Offset(0, softwareCol)

                    ' Unique Code '
                    If targetSoftware = cell.Value &amp; " " Then
                        cell.Rows.Hidden = False
                    End If

                Next
            End If
        Next softwareCol

        ' Unique Code '
        .Activate
        .Range("A1").Select

    End With
End Sub
What you want to do is called refactoring - combining similar methods into a single function.

You have two loops-

 For softwareCol = 0 To 10
 Next softwareCol

 For softwareCol = 0 To 5
      If Not (softwareCol = 2 Or softwareCol = 4)
 Next softwareCol


I don't see an easy way to eliminate those loops. 



Let's focus on what you want to combine

If targetSoftware = cell.Value &amp; " " &amp; cell.Offset(0, 1).Value Then
   cell.Rows.Hidden = False
End If
If targetSoftware = cell.Value &amp; " " Then
   cell.Rows.Hidden = False
End If


You can do this in a boolean function -

Private Function NeedsToHide(ByVal targetSoftware As String, ByVal firstValue As String, Optional ByVal secondValue As String = vbNullString) As Boolean
    If targetSoftware = firstValue &amp; " " &amp; secondValue Then
        NeedsToHide = False
    Else
        NeedsToHide = True
    End If
End Function


So now it's just

 For softwareCol = 0 To 10
    'etc
    cell.Rows.Hidden = NeedsToHide(targetSoftware, cell.Value, cell.Offset(0, 1).Value)
 Next softwareCol

 For softwareCol = 0 To 5
    'etc
     cell.Rows.Hidden = NeedsToHide(targetSoftware, cell.Value)
 Next softwareCol