{"id":16,"date":"2007-02-27T16:39:51","date_gmt":"2007-02-27T15:39:51","guid":{"rendered":"http:\/\/www.crydust.be\/blog\/2007\/02\/27\/removing-rows-in-excel\/"},"modified":"2007-05-11T00:50:25","modified_gmt":"2007-05-10T23:50:25","slug":"removing-rows-in-excel","status":"publish","type":"post","link":"http:\/\/www.crydust.be\/blog\/2007\/02\/27\/removing-rows-in-excel\/","title":{"rendered":"Removing rows in Excel"},"content":{"rendered":"<p>Today I had to remove all rows in an excel sheet containing #N\/A in the third cell. The only catch is that there are thousands and thousands of these rows and I need to be able to repeat this action.<\/p>\n<p><!--more--><\/p>\n<pre><code>Sub RemoveBadOnes()\r\n    \r\n    'speed things up\r\n    Application.ScreenUpdating = False\r\n    Application.Calculation = xlCalculationManual\r\n    \r\n    Dim sheetName As String\r\n    sheetName = \"copy of clean\"\r\n    \r\n    'get number of non-empty rows\r\n    '(probably not the most optimal way to do this)\r\n    Dim numRows As Integer\r\n    numRows = 1\r\n    Do While Not IsEmpty(Worksheets(sheetName).Cells(numRows, 1).Value)\r\n        numRows = numRows + 1\r\n    Loop\r\n    \r\n    'go trough rows starting with the last one\r\n    Dim counter As Integer\r\n    For counter = numRows To 1 Step -1\r\n        'remove each row containing #N\/A in third cell\r\n        If IsError(Worksheets(sheetName).Cells(counter, 3).Value) Then\r\n             Worksheets(sheetName).Rows(counter).Delete\r\n        End If\r\n    Next counter\r\n    \r\n    'return control to the user\r\n    Application.Calculation = xlCalculationAutomatic\r\n    Application.ScreenUpdating = True\r\n    \r\nEnd Sub<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I had to remove all rows in an excel sheet containing #N\/A in the third cell. The only catch is that there are thousands and thousands of these rows and I need to be able to repeat this action.<\/p>\n<p> <a href=\"http:\/\/www.crydust.be\/blog\/2007\/02\/27\/removing-rows-in-excel\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crydust.be\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}