How to change macro to hide cells equal to zero?

deb0578

Board Regular
Joined
Sep 8, 2010
Messages
62
I am new to Excel. I am trying to write a macro that (1) does an alphabetical sort for rows 9 through 50 (based on the contents in Column B; (2) Put the rows that have a zero in Column B at the bottom of the sort; and then (3) hide those rows that have a zero in Column B.

Below is my code that does not accomplish this. Can someone point me in the right direction?

Thank you in advance for your help.

--------------

Sub Macro2()
'
' Macro2 Macro
'
'
Range("A9:A50").EntireRow.Hidden = False
On Error Resume Next
Range("A9:A50").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
Rows("9:50").Select
Selection.EntireRow.Hidden = False

ActiveWorkbook.Worksheets("2nd Qtr 2012").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("2nd Qtr 2012").Sort.SortFields.Add Key:=Range("B9" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("2nd Qtr 2012").Sort
.SetRange Range("B9:AH50")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
Range("A9:A50").EntireRow.Hidden = False
On Error Resume Next
Range("b9:b49").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True

End With
Range("D3").Select
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Macro2()<br>                                              <br>    <SPAN style="color:#00007F">Dim</SPAN> Lastrow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>                                              <br>    <SPAN style="color:#00007F">With</SPAN> Worksheets("2nd Qtr 2012")<br>    <br>        <SPAN style="color:#00007F">If</SPAN> .FilterMode <SPAN style="color:#00007F">Then</SPAN> .ShowAllData<br>        .Rows.Hidden = <SPAN style="color:#00007F">False</SPAN><br>        <SPAN style="color:#007F00">'Lastrow = Range("B" & Rows.Count).End(xlUp).Row</SPAN><br>        Lastrow = 50<br>        <br>        .Range("A9:AH" & Lastrow).Sort Key1:=Range("B9"), _<br>                  Order1:=xlAscending, Header:=xlGuess, _<br>                  OrderCustom:=1, MatchCase:=False, _<br>                  Orientation:=xlTopToBottom, _<br>                  DataOption1:=xlSortNormal<br>        <br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>        .Range("B9:B" & Lastrow).SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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