Good morning,
I seem to have run into a problem with how my rngVisible is defined - there is a header in rngSource in Row2, that is the reason for why I offset by one row. I have also checked the filter applied and they are being applied correctly during each loop.
I have added two debug lines to see the first and last visible cell in the source list after applying the filters and for some reason it only detects the first visible cell in column A - A13 and last visible cell detected is also A13, when in reality the first on the rngSource is A13, but the last visible cell is A222
This causes my For counter loop to skip the copy part of the code since agents variable in this case is 10, counter goes higher than the one visible cell (A13)
Could anyone kinldy help?
'Agents Loop
For i = 6 To ThisWorkbook.Worksheets("Pivot").UsedRange.Rows.Count
country = ThisWorkbook.Worksheets("Pivot").Cells(i, 7).Value
agents = ThisWorkbook.Worksheets("Pivot").Cells(i, 10).Value
rngSource.AutoFilter Field:=16, Criteria1:=country, Operator:=xlFilterValues
rngSource.AutoFilter Field:=25, Criteria1:="3", Operator:=xlFilterValues
rngSource.AutoFilter Field:=26, Criteria1:="No", Operator:=xlFilterValues
rngSource.AutoFilter Field:=23, Criteria1:="HR services", Operator:=xlFilterValues
rngSource.Sort Key1:=rngSource.Columns(27), Order1:=xlAscending, Header:=xlYes
On Error Resume Next
Set rngVisible = rngSource.Offset(1, 0).Resize(rngSource.Rows.Count - 1).Columns(1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
Set copyDestination = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1, 0)
If copyDestination.Row < 3 Then
Set copyDestination = wsDest.Range("A3")
End If
For counter = 1 To agents
If counter <= rngVisible.Rows.Count Then
rngVisible.Cells(counter).Copy copyDestination
Set copyDestination = copyDestination.Offset(1, 0)
End If
Next counter
wsSource.AutoFilterMode = False
Next i
I seem to have run into a problem with how my rngVisible is defined - there is a header in rngSource in Row2, that is the reason for why I offset by one row. I have also checked the filter applied and they are being applied correctly during each loop.
I have added two debug lines to see the first and last visible cell in the source list after applying the filters and for some reason it only detects the first visible cell in column A - A13 and last visible cell detected is also A13, when in reality the first on the rngSource is A13, but the last visible cell is A222
This causes my For counter loop to skip the copy part of the code since agents variable in this case is 10, counter goes higher than the one visible cell (A13)
Could anyone kinldy help?
'Agents Loop
For i = 6 To ThisWorkbook.Worksheets("Pivot").UsedRange.Rows.Count
country = ThisWorkbook.Worksheets("Pivot").Cells(i, 7).Value
agents = ThisWorkbook.Worksheets("Pivot").Cells(i, 10).Value
rngSource.AutoFilter Field:=16, Criteria1:=country, Operator:=xlFilterValues
rngSource.AutoFilter Field:=25, Criteria1:="3", Operator:=xlFilterValues
rngSource.AutoFilter Field:=26, Criteria1:="No", Operator:=xlFilterValues
rngSource.AutoFilter Field:=23, Criteria1:="HR services", Operator:=xlFilterValues
rngSource.Sort Key1:=rngSource.Columns(27), Order1:=xlAscending, Header:=xlYes
On Error Resume Next
Set rngVisible = rngSource.Offset(1, 0).Resize(rngSource.Rows.Count - 1).Columns(1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
Set copyDestination = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1, 0)
If copyDestination.Row < 3 Then
Set copyDestination = wsDest.Range("A3")
End If
For counter = 1 To agents
If counter <= rngVisible.Rows.Count Then
rngVisible.Cells(counter).Copy copyDestination
Set copyDestination = copyDestination.Offset(1, 0)
End If
Next counter
wsSource.AutoFilterMode = False
Next i