Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am a complete newbie to Excel so please excuse me if this is something easy to do. I have looked through a lot of options but couldn't find what I needed.

Basically, I want to delete all of the rows that don't contain a value in column C. How would I go about doing this?

I am doing this manually right now for 5000+ products and it's driving me insane.

share|improve this question

migrated from stackoverflow.com Sep 15 '12 at 13:05

This question came from our site for professional and enthusiast programmers.

    
Why was a question asked on Stack OverFlow with VBA solutions migrated to Super User? –  brettdj Sep 16 '12 at 6:58

5 Answers 5

You can do this very quickly if the cells are truly blank using SpecialCells

Manual

  • Select Column C
  • Press F5, then Special
  • check blanks, then ok (see this step in the pic at bottom)
  • delete the rows that are now selected

VBA

Sub QuickCull()
On Error Resume Next
Columns("C").SpecialCells(xlBlanks).EntireRow.Delete
End Sub

enter image description here

share|improve this answer

Here's an easy manual method

  1. Apply an Auto Filter to your sheet
  2. Filter on column C Blank
  3. Select all visible rows
  4. Delete Rows
  5. Remove filter

This process can be automated with VBA if required. Try running the macro recorder to get a start

share|improve this answer

I think the easiest thing assuming you don't have a bunch of other formulas in the other cells is to just sort everything by Column C and then delete all the rows that have a blank for column C(the sort function will put the blank values for column C at the top of the file).

In summary:

  • Click on the folded paper cell above cell marked "1" and to the left of cell marked "A" (to highlight all)
  • Click on Data, and then sort
  • Sort by Column C, and make smallest values be first
  • Just highlight the rows down until you hit the first row with a value for Column C, and delete everything you highlighted
share|improve this answer

Here's some code that seems to do what you want: http://www.ozgrid.com/VBA/VBACode.htm

Here's an excerpt:

Sub DeleteBlankRows1()
    'Deletes the entire row within the selection if the ENTIRE row contains no data.

    'We use Long in case they have over 32,767 rows selected.

    Dim i As Long 

    'We turn off calculation and screenupdating to speed up the macro.

     With Application
         .Calculation = xlCalculationManual
         .ScreenUpdating = False

         'We work backwards because we are deleting rows.

         For i = Selection.Rows.Count To 1 Step -1
              If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
                  Selection.Rows(i).EntireRow.Delete
              End If
         Next i

        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
End Sub
share|improve this answer
    
This doesn't address the question. It deletes rows where the entire row is blank - the question referred to column C only –  brettdj Sep 15 '12 at 6:09

You can put this code in Sheet Module (Right Mouse Click Sheet Tab and select "View Code"):

Sub Delete_Blank_Rows()


'Deletes the entire row within the selection if the ENTIRE row contains no data.

'We use Long in case they have over 32,767 rows selected.

Dim i As Long
Dim LastRow As Integer

'We turn off calculation and screenupdating to speed up the macro.

 With Application
     .Calculation = xlCalculationManual
     .ScreenUpdating = False

     'Reduce the work on the calc and define the range

     LastRow = Range("A" & Rows.Count).End(xlUp).Row
     Range("A2:A" & LastRow).Select

     'We work backwards because we are deleting rows.

     For i = Selection.Rows.Count To 1 Step -1
          If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
              Selection.Rows(i).EntireRow.Delete
          End If
     Next i

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With

End Sub
share|improve this answer
1  
This deletes rows where the entire row is blank? -if does, it's similar to @drnewman answer. Question specifically states: Delete row if cell in certain column is blank. –  Davidenko Mar 22 at 12:12
    
Welcome to Super User! Please read the question again carefully. Your answer does not answer the original question. –  DavidPostill Mar 22 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.