How to write If any cells in Column X = 0 Cut entire rows

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
I have been relying on find and replacing specific values (in this case 0 with nothing) and then using special select entire (blanks.entirerow) which is janky code and doesn't work without an error wrap in case the special select finds nothing.

An If and else statement would be more elegant.

So Column X:X If cell = 0 select that entire row in order to cut it and paste in elsewhere.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You could use autofilter for that.
 
Upvote 0
You could filter column X on values equalling zero and then cut the visible range and paste elsewhere.
 
Upvote 0
Why don't you want to use an autofilter?
It will be far simpler & probably quicker
 
Upvote 0
The problem I have with autofilter is the defined ranges it uses; in this case $A$1:$AB$7; I think i have worked out a version in the past that does not write the ranges but I don't have it on hand right now.

Also the Rows 8:30 I selected after the filtering is specific and not dynamic and I don't know how to select the results of a filtered range if the range it produces will always be unique.

Code:
'
    Cells.Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$AB$7").AutoFilter Field:=24, Criteria1:="=0", _
        Operator:=xlAnd
    Rows("8:30").Select
    Selection.Copy
 
Upvote 0
As long as you don't have any blank rows in the data, you can use
Code:
Sub Tardisgx()
   With ActiveSheet
      .Range("A1:AB1").AutoFilter 24, "0"
      With .AutoFilter.Range.Offset(1).EntireRow
         .Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
         .Delete
      End With
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
That is so small I read it like it's skipping steps and doing 2 steps in 1 line. It's brilliant thanks.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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