Question on Hiding Row Conidtionally

trm1838

New Member
Joined
Aug 31, 2006
Messages
1
Hi

I want VBA to hide rows conditionally based on a column in that row being equal to 0, but i want it to automaticallly include all active rows with data in the spreadsheet instead of entering a range. Then i want it to sort the data in descending order. Any help would be great.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi, trm1838
Welcome to the Board !!!!!

Some suggestions to start with:
Do you know about the tools AutoFilter & Sort in the menu Data ?
Do you know about the macro recorder ?

when recording a macro, you'll get something like this
Code:
Sub Macro1()

    Range("A1:C10").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=1, Criteria1:="<>0", Operator:=xlAnd
    Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
End Sub
a few edits
recoreded macro has all arguments
one of them is "Header" recorded result:=xlGuess
if there are headers then you need Header:=xlYes, if not xlNo
I assume there are headers
Code:
Sub Macro1_edit1()

    With Range("A1:C10")
    .AutoFilter
    .AutoFilter Field:=1, Criteria1:="<>0", Operator:=xlAnd
    .Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    End With

End Sub
this is what we call hardcoding
now you can do a search for "lastrow" to see how you would edit this to change "10" to the real last row

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,226,246
Messages
6,189,858
Members
453,575
Latest member
Taljanin

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