title: VBA Filtering Loop in Loop
body: <p>I found this code, it was only for one column to find all unique values, and filter them,copy/paste in filtered values named sheet. </p>
  
  <p>But what I need to do, is filter two columns, and name it by the same principles, so I modified it.</p>
  
  <p>Somehow on second value in first loop, it doesnt start loop in other loop.</p>
  
  <p>Why does it give me blanks in second loop?</p>
  
  <pre><code>Sub datu_sagrupesana()
  Dim x As Range, y As Range, rng As Range, last As Long, sht As Worksheet
  
  Application.ScreenUpdating = False
  
  
  'datu vieta
  Set sht = ThisWorkbook.Worksheets("Test")
  
  'apgabals
  
  last = sht.Cells(Rows.Count, "A").End(xlUp).Row
  Set rng = sht.Range("A1:C" &amp; last)
  
  sht.Range("A1:A" &amp; last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("H1"), Unique:=True 'produkta filtrs
  sht.Range("C1:C" &amp; last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("J1"), Unique:=True 'valodas filtrs
  
  For Each y In Range([J2], Cells(Rows.Count, "J").End(xlUp))
  
  For Each x In Range([H2], Cells(Rows.Count, "H").End(xlUp))
  
  With rng
  .AutoFilter
  .AutoFilter Field:=3, Criteria1:=y.Value
  .AutoFilter Field:=1, Criteria1:=x.Value
  .SpecialCells(xlCellTypeVisible).Copy
  
  Sheets.Add(After:=Sheets(Sheets.Count)).Name = y.Value &amp; x.Value
  ActiveSheet.Paste
  End With
  
  Next x
  Next y
  
  
  'nonemt filtru
  sht.AutoFilterMode = False
  
  With Application
  .CutCopyMode = False
  .ScreenUpdating = True
  End With
  
  End Sub
  </code></pre>