+ Reply to Thread
Results 1 to 21 of 21

EXCEL VBA deleting empty rows code with formulas

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    EXCEL VBA deleting empty rows code with formulas

    Hi

    I have this really simple code...

    Please Login or Register  to view this content.
    Unfortunately the range it is looking at is full of formulas and therefore the code isnt working properly.

    What am i doing wrong??

    I know there's an easy answer for this ans i'm going to kick myself when i find out!!

    Thanks

  2. #2
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: EXCEL VBA deleting empty rows code with formulas

    If you are wanna delete row a having formulas then use following code..

    Dim i As Integer

    Please Login or Register  to view this content.
    you can also use OR instead of and

    Don't forget to click *

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: EXCEL VBA deleting empty rows code with formulas

    If you don't and to delete use..

    Please Login or Register  to view this content.

    Don't forget to click *

  4. #4
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: EXCEL VBA deleting empty rows code with formulas

    I didnt explain it very well...

    I'm trying to delete the rows that DO NOT have a "1" in it.

    however all the rows create the "1" by formula.

    I'm trying to look at the VALUE rather than the CELL CONTENTS but i'm not sure how to do it!?

  5. #5
    Registered User
    Join Date
    09-01-2012
    Location
    necessary rq
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: EXCEL VBA deleting empty rows code with formulas

    Pl send sample of your file.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    Super,
    It is easier and faster to use a filter than a loop, but if you want to delete a row, you need to loop back ward, not forward.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: EXCEL VBA deleting empty rows code with formulas

    Try this...

    Please Login or Register  to view this content.
    Don't forget to click *

  8. #8
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: EXCEL VBA deleting empty rows code with formulas

    None of the above worked...sorry

    but i've figured out whats happening - because the loop goes through each line, its missing every other line out that equals the required value!!!

    hence why its not deleting all the lines i need.

    is there a way round this?

    thanks

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    It is also possible that the value you try to exclude is 1, not "1".
    If this does not work, please attach a sample and will be solved in no time.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: EXCEL VBA deleting empty rows code with formulas

    Didn't work either! sorry

    I have attached a sample of the sheet - hopefully you can see what i'm trying to do from the macro.

    The first parts work fine, its just this - deleting the blank lines - on sheet1 i'm struggling with.

    any help would be great.

    TVM
    Attached Files Attached Files
    Cry Havoc, let loose the Dogs of War

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    Super,
    You have formula in sheet1, in column A. What exactly do you want to do? Do you want to delete empty rows, or values which are not 1? Please explain.

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    This code deletes any cell with out error and if the cell value is not 1. It works.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: EXCEL VBA deleting empty rows code with formulas

    Nice one!

    the only other thing is that, because of how i've done the formulas for the headings, they are still appearing with a #REF error in column A which doenst get deleted.

    Do you think there is any way around this?

  14. #14
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: EXCEL VBA deleting empty rows code with formulas

    Another, more efficient way:
    Please Login or Register  to view this content.
    /berlan
    Last edited by berlan; 07-31-2014 at 11:14 AM.

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    The most efficient way is to use filter, but first you need to include if error in your fromula to remove the errors.
    =IFERROR(IF(T211=0,0,1),0).
    You do not even a code for this simple task.

  16. #16
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: EXCEL VBA deleting empty rows code with formulas

    Is that what i should use in column A?

  17. #17
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: EXCEL VBA deleting empty rows code with formulas

    AB33, I agree, but as long as you delete the rows at the same time, as in my routine, you won't get any errors in the first place.

  18. #18
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    Any where! If you have a formula and for what ever reason, the formula returns an error, you can replace the error with something, in this case with 0, but you can use any value instead of the error. It is an excel function post 2007.

  19. #19
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: EXCEL VBA deleting empty rows code with formulas

    Well, you've both been a great help. the sheets doing exactly what I need now!!!

    thanks again!

  20. #20
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: EXCEL VBA deleting empty rows code with formulas

    Hi Berlan,
    Yes, your code is much faster than a for each loop, but a filter is much faster as you do not need to loop at all. I have already pointed out this on post 5.

  21. #21
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: EXCEL VBA deleting empty rows code with formulas

    AB33, I can see that

    For a filter routine, this code takes me 0.268 seconds (vs. 0.32 seconds for my other code in post #14):

    Please Login or Register  to view this content.
    Best,
    berlan

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Code/Macro for deleting empty columns and rows.
    By gautamacharya in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 01:49 PM
  2. [SOLVED] Deleting empty rows in excel using macro
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2013, 02:40 AM
  3. Deleting empty rows if specific cell in row is empty
    By csynic in forum Excel General
    Replies: 0
    Last Post: 07-06-2011, 01:43 AM
  4. Autofilter/delete empty rows is deleting non-empty rows!
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2010, 12:31 PM
  5. Deleting Empty Rows in Excel
    By VexedFist in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2006, 02:25 PM

Tags for this Thread

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