+ Reply to Thread
Results 1 to 10 of 10

Delete Row

Hybrid View

  1. #1
    Registered User
    Join Date
    11-10-2006
    Posts
    20

    Delete Row

    Hi

    I want to check a worksheet where column C has figures entered. How do I check this column and if it is blank or has a 0 (zero) entered in it, the row is deleted. The range is A9:E119 for the whole work sheet and the Column range is C9:C119.

    I have tried to write it mylef but I just dont know enough yet.

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Hi just add a module and paste this in, you can either run it via a command button or give it a keyboard shortcut

    Sub removeblank()
    Dim Rng As Range
    Dim MyCell
    Dim i
    i = 1
    Set Rng = Range("C9:C119")
    For Each MyCell In Rng
    If MyCell = Null Or MyCell = 0 Then
    MyCell.EntireRow.Delete
    End If
    i = i + 1
    Next
    MsgBox "There were " & i & " Rows Deleted!"
    End Sub
    Regards,
    Simon

  3. #3
    Registered User
    Join Date
    11-10-2006
    Posts
    20
    Hi Simon

    Many thanks for the help, when I run the code I get this error:

    Delete method of Range class failed

    and when I press debug it highlights this line:

    MyCell.EntireRow.Delete

    Regards

    Alan

  4. #4
    Forum Contributor
    Join Date
    08-19-2006
    Posts
    116
    Hi Alan

    And what do you think of this?

    Sub Delete()
    For i = 9 To 119
    For j = 3 To 3
    If Cells(i, j) = "0" Or Cells(i, j) = "" Then
    Rows(i).Delete
    End If
    Next j
    Next i
    End Sub
    Last edited by Raiby; 11-17-2006 at 01:48 PM.

  5. #5
    Registered User
    Join Date
    11-10-2006
    Posts
    20
    Hi Raiby

    Thanks for the code, I cannot get it to work.

    Alan

  6. #6
    Forum Contributor
    Join Date
    08-19-2006
    Posts
    116
    Hi Alan

    Did you see my correction?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1