ShowAllData Error

Squid1930

New Member
Joined
Sep 23, 2015
Messages
1
Hi,

I have a macro that automatically creates a validation list depending on the cell to the left of it. The cell to the left is a category for a price list. The price list is on a separate worksheet, so the macro filters the price list, copies it to another worksheet (FilterSheet) and then creates the validation list from this.

The problem is that it works for rows above about 230 (this changes by a few rows) but doesn't work for rows below this.

The error is on the ps.ShowAllData

If I click Debug error then scroll to the top of the worksheet before clicking continue it then continues to work.

The code is

Code:
Sub Filter(sh As Worksheet, rn As String)
    


Application.ScreenUpdating = False


Dim fs As Worksheet
Dim ps As Worksheet
Dim lRow As Double


Set fs = Worksheets("FilterSheet")
Set ps = Worksheets("Price List")


lRow = ps.Cells(1, 2).End(xlDown).Row


ps.ListObjects("Table2").Range.AutoFilter Field:=9, Criteria1:=sh.Range(rn).Value


fs.Range("A1:A10000").ClearContents


ps.Range("B1:B" & lRow).Copy
fs.Range("A1").PasteSpecial xlPasteValues




If Not WorksheetFunction.CountA(fs.Range("A1:A10000")) = 1 Then


    Dim p As Integer
    
    p = fs.Cells(1, 1).End(xlDown).Row
    
    With sh.Range(rn).Offset(0, 1).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="='FilterSheet'!$A$2:$A$" & p
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
Else
    With sh.Range(rn).Offset(0, 1).Validation
            .Delete
    End With
End If


'Application.Goto ps.Range("A1")
If ps.FilterMode Then
    ps.ShowAllData
End If
'Application.Goto sh.Range(rn).Offset(0, 1)


ps.Range("A1").Copy
Application.CutCopyMode = False


End Sub

If I include the Application.Goto before and after (currently commented out) then it works. So that is my work around for now but it doesn't address the problem.

I have recreated the problem on another worksheet with nothing but 2 entries, one on row 4 and another on row 330.
I can send it to anyone that wants to see it.

Thanks in advance
Sam
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top