VBA Unsort Show All Data

Tuckejam

Board Regular
Joined
Oct 15, 2013
Messages
81
One of the things I always try to do with my workbooks is to build a Macro button that re-writes all of the formulas and brings everything back to the way it was when it was opend (without affecting the data that has been entered into the workbook)

This way if someone really messes something up the can click the button instead of calling me!

Anyway the problem i am running to now is that i need to make sure the worksheet is unsorted before the macro rewrites all of the formulas.

So I use this

Code:
   Sheets("Assortment").Select
   ActiveSheet.ShowAllData

The problem is if the data has not been sorted in some way then i get an

Run -ime Error '1001':
ShowAllData method of worksheet class failed

anyone now a way to get around this.

maybee as simple as an

"if worksheet is sorted then ActiveSheet.ShowAllData"

but i dont know how to write that.

Thanks as always to everyone here. I am always amazed the the absolut brilliant solutions people help me with.

Thanks
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,336
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Doesn't ShowAllData apply to filter and not sort?
Anyway if it is the filter you mean then try something like...

Code:
  If ActiveSheet.AutoFilterMode Or ActiveSheet.FilterMode Then
            ActiveSheet.ShowAllData
        End If
 

Tuckejam

Board Regular
Joined
Oct 15, 2013
Messages
81
You are absolutly correct i was using the wrong word. I am refering to filtering.

Howver im still getting the same error when i tried that peice of code you sugested

Thanks again
 

Tuckejam

Board Regular
Joined
Oct 15, 2013
Messages
81
I got it i just wrote the macro to filter to something first then show all data.

Thanks again for you help though
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,336
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Try testing the code below to see if it does what you want

Rich (BB code):
Sub TestFilt()
    Dim rngFilter As Range, rngF As Long, Frng As Long

    If ActiveSheet.AutoFilterMode Or ActiveSheet.FilterMode Then
        Set rngFilter = ActiveSheet.AutoFilter.Range
        rngF = rngFilter.Rows.Count
        Frng = rngFilter.SpecialCells(xlCellTypeVisible).Count

        If rngF > Frng Then ActiveSheet.ShowAllData
    End If

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,359
Messages
5,528,226
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top