Help writing simple code

thewiseguy

Well-known Member
Joined
May 23, 2005
Messages
803
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

Trying to write a simple code. Here is what I am trying to do:

In sheet "DETAIL1" from cell B4 to B316, wherever the value is "0," clear the contents of the entire row (but not column A).

Hope that is clear and any help is greatly appreciated!


-twg
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
47,926
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

Trying to write a simple code. Here is what I am trying to do:

In sheet "DETAIL1" from cell B4 to B316, wherever the value is "0," clear the contents of the entire row (but not column A).

Hope that is clear and any help is greatly appreciated!


-twg
Try this. I'm assuming there is something in B3.

<font face=Courier New><br><br><SPAN style="color:#00007F">Sub</SPAN> ClearZeroRows()<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Sheets("DETAIL1").Range("B3:B316").Resize(, Columns.Count - 1)<br>        .AutoFilter Field:=1, Criteria1:="=0"<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>            .Offset(1).Resize(313).SpecialCells(xlCellTypeVisible).ClearContents<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br>        .AutoFilter<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 

thewiseguy

Well-known Member
Joined
May 23, 2005
Messages
803
Office Version
  1. 365
Platform
  1. Windows
Try this. I'm assuming there is something in B3.

<font face=Courier New><br><br><SPAN style="color:#00007F">Sub</SPAN> ClearZeroRows()<br>****Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>****<SPAN style="color:#00007F">With</SPAN> Sheets("DETAIL1").Range("B3:B316").Resize(, Columns.Count - 1)<br>********.AutoFilter Field:=1, Criteria1:="=0"<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>************.Offset(1).Resize(313).SpecialCells(xlCellTypeVisible).ClearContents<br>********<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br>********.AutoFilter<br>****<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>****Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>



that worked perfectly peter...thank you.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,085
Messages
5,599,650
Members
414,325
Latest member
kfg1287

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
Top