Sub RepStats()

D

David A.

I have this macro that I am trying to run:
Sub RepStats()
On Error Resume Next
Dim rng As range
Set myrng = Worksheets("Rep Page").range("A:A")
For Each c In myrng
If c <> "" Then
Sheets("Rep Page").Select
Sheets("Sheet1").Select
Selection.AutoFilter Field:=2, Criteria1:=c.Value
With ActiveSheet.AutoFilter.range
On Error Resume Next
Set rng11 = .Offset(1, 0).Resize(.Rows.Count - 1, _
1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng11 Is Nothing Then
MsgBox em + " **No Data Found For This Rep**"
Else
range("B:B").EntireColumn.Hidden = True
Set rng = ActiveSheet.AutoFilter.range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Rep Page").range(c.Address).Offset(0, 1)
End If
ActiveSheet.ShowAllData
Sheets("Rep Page").Select
End If
Next
End Sub

The thing is that it does everything except:
With ActiveSheet.AutoFilter.range
On Error Resume Next
Set rng11 = .Offset(1, 0).Resize(.Rows.Count - 1, _
1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng11 Is Nothing Then
MsgBox em + " **No Data Found For This Rep**"

Jt just goes to:
Else
range("B:B").EntireColumn.Hidden = True
Set rng = ActiveSheet.AutoFilter.range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Rep Page").range(c.Address).Offset(0, 1)
End If

And copies the entire sheet, not the filtered data.

HElp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top