Retype Macro to run properly

Ramadan2512

New Member
Joined
Sep 7, 2024
Messages
40
Office Version
  1. 2021
Platform
  1. Windows
I have recorded a Macro to re-arrange my table with color and to sort row by date Ascending but later I needed to add 03 rules to remove all filters in the table to show all data then to go to the last row in table and to save the workbook but it seems that they need to be set in a professional way to run smoothly and properly because it gives me an error in this area - so I need a help to do that please
here is my code
VBA Code:
[
Sub Rearrange()

    Range("B8:K8").Select
    Selection.Copy
    Range("Table1").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("Data").ListObjects("Table1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Data").ListObjects("Table1").Sort.SortFields.Add( _
        Range("Table1[[#All],[Column10]]"), xlSortOnCellColor, xlAscending, , _
        xlSortNormal).SortOnValue.Color = RGB(146, 208, 80)
    With ActiveWorkbook.Worksheets("Data").ListObjects("Table1").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
     ActiveSheet.ShowAllData
     ThisWorkbook.Save
    Selection.End(xlDown).Select
End Sub

]
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi @Ramadan2512, when you say "remove all filters", you mean make sure no filter is active, not completely remove the filter? If so:

Code:
Selection.AutoFilter

Will toggle the Filter on and off.

Then to go to the last row in table and to save the workbook​

Yep, you have those steps -

VBA Code:
ThisWorkbook.Save
Selection.End(xlDown).Select
 
Upvote 0
Hi @Ramadan2512, when you say "remove all filters", you mean make sure no filter is active, not completely remove the filter? If so:

Code:
Selection.AutoFilter

Will toggle the Filter on and off.


Yep, you have those steps -

VBA Code:
ThisWorkbook.Save
Selection.End(xlDown).Select
thanks for your reply - in my table there are filters that I use sometine to search data so I need the marco when clicked to show all the table data not only filtered rows so I used (ActiveSheet.ShowAllData) then to save the workbook and finally to go to the last row to let me enter you data
 
Last edited:
Upvote 0
thanks for your reply - in my table there are filters that I use sometine to search data so I need the marco when clicked to show all the table data not only filtered rows so I used (ActiveSheet.ShowAllData) then to save the workbook and finally to go to the last row to let me enter you data
Looks like when you combine those three, you have it covered! The only other thing I could think would be to turn off screenupdating so it all happens in the blink of an eye.
 
Upvote 0
If you add a bit more code it will handle the situation where the filter buttons have been turned off on the table:
VBA Code:
    With ActiveWorkbook.Worksheets("Data").ListObjects("Table1")
        If .ShowAutoFilter = True Then
            .AutoFilter.ShowAllData
        End If
    End With
 
Upvote 0
Solution
If you add a bit more code it will handle the situation where the filter buttons have been turned off on the table:
VBA Code:
    With ActiveWorkbook.Worksheets("Data").ListObjects("Table1")
        If .ShowAutoFilter = True Then
            .AutoFilter.ShowAllData
        End If
    End With


[/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,145
Members
452,615
Latest member
bogeys2birdies

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