Easy Macro Question

seanbanks

New Member
Joined
Apr 8, 2009
Messages
12
Hi all,

I'm trying to figure out a macro and I'm sure its an easy fix but I can't figure it out. I need to delete all rows when a specific column has a blank cell. The problem is that column isn't always the same. But it always has the same name, "keep_it".

In summary, I need to find a column "keep_it" and delete all rows in which "keep_it" has blank values, but in some worksheets "keep_it" is in column C (for example) and in others it is in a different location.

Thank you in advance,
Sean
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
try this
Code:
Sub test()
 Dim theRange As Range
 Dim nCells As Integer
 Dim I As Integer
Range("keep_it").Activate
  Range(ActiveCell, cells(65536, ActiveCell.Column) _
 .End(xlUp)).Select
   Set theRange = Selection
   nCells = theRange.cells.Count
   For I = nCells To 1 Step -1
     If theRange.cells(I).Value = 0 Then
        theRange.cells(I).EntireRow.Delete
     End If
   Next
End Sub
 
Upvote 0
it works for me i named the column Range keep_it, what excel V you have. i can send you the work book to look at it.
 
Upvote 0
excel 7 the new one? if so you will need to fix the max i am useing excel 2000. the max rows is 65563.
 
Upvote 0
looks like adding this line at the beginning of your first macro will work...

Range(Selection, Selection.SpecialCells(xlLastCell)).Select

?
 
Upvote 0

Forum statistics

Threads
1,215,868
Messages
6,127,408
Members
449,382
Latest member
DonnaRisso

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