+ Reply to Thread
Results 1 to 8 of 8

If/Then Code for deleting rows

  1. #1
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    If/Then Code for deleting rows

    I'm trying to write some basic code to check if cell A6 has any value (could be a string too). If A6 has a value, then I want to delete Rows 1:5. If A6 does not have a value and is blank, then I don't want the macro to do anything. I have posted my sample code below. I feel like this should be really easy, but the macro deletes rows 1:5 regardless of whether A6 has a value or not. Any help with a fix is much appreciated!

    Please Login or Register  to view this content.

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

    Re: If/Then Code for deleting rows

    Range("A6"). may not be blank.
    Do you have a formula with null string in A6?

  3. #3
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: If/Then Code for deleting rows

    Or are there spaces in A6?
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: If/Then Code for deleting rows

    there is a ISEMPTY and ISNULL in VBA that lets you check....

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

    Re: If/Then Code for deleting rows

    TRY,

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: If/Then Code for deleting rows

    Or maybe:
    Please Login or Register  to view this content.
    Click the * to give Rep to a post you like.

  7. #7
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: If/Then Code for deleting rows

    I'm not quite xpert, but If I understand you correct, you just need to delete rows If A6 has a value. Then everything you have to do Is change "A6" to both ranges :

    Please Login or Register  to view this content.
    but It deletes A6 too, you want that ?
    Last edited by Lukael; 03-10-2014 at 03:00 PM.

  8. #8
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: If/Then Code for deleting rows

    AB33's code worked! To confirm, the cell did infact have a SPACE in it so it was capturing this value and not categorizing it as truly blank. I'm assuming the TRIM and NullString components of the fixed code are taking this into account. Much thanks for your help!

    Please Login or Register  to view this content.

+ 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. Changing code from deleting rows to cut/paste rows into another sheet and delete blank row
    By kmarshall6576 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2013, 01:54 AM
  2. [SOLVED] VBA Code for Deleting 2 Rows Repetitively
    By kitcargray in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2012, 10:36 AM
  3. Need VBA Code for Adding / Deleting Rows
    By sambuka in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2012, 11:14 AM
  4. speedup the code for deleting rows
    By maheshwow in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-17-2012, 02:41 PM
  5. Deleting Duplicate rows...VBA Code
    By robkozak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2008, 03:46 PM

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