+ Reply to Thread
Results 1 to 7 of 7

If selection contains any value then

  1. #1
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    178

    If selection contains any value then

    Hi,

    I am trying to modify my VBA code in a way so it wont delete selection if selection contains any text or value.
    I have bolded the text in my code.

    Please Login or Register  to view this content.
    Thanks for any help I can get.
    B.

  2. #2
    Registered User
    Join Date
    06-03-2015
    Location
    Houston, Tx
    MS-Off Ver
    2010
    Posts
    64

    Re: If selection contains any value then

    Please Login or Register  to view this content.
    Last edited by jonathann3891; 09-17-2018 at 08:17 AM.

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,777

    Re: If selection contains any value then

    Try:
    Please Login or Register  to view this content.
    Basically, the macro deletes the rows only if the range is blank.
    Last edited by Mumps1; 09-17-2018 at 09:21 AM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  4. #4
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    178

    Re: If selection contains any value then

    Hi,

    I tried your code and it works well. Can I modify your code so it deletes empty rows, but not the rows with values or text within range?
    It would be nice if it also detects a row that contains value X1 because this row should not be deleted.
    And if I run the code for the second time and all the rows in range contains values or text than the messagebox would popup "The rows contains values"

    The reason I would like to modify the code is that when sheet contains many blank rows and within that range is just one row that contains text, so I get stuck with empty rows

    I hope I explained well.

    Thank you for helping.
    B.
    Last edited by besis; 09-17-2018 at 04:34 PM.

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,777

    Re: If selection contains any value then

    The macro is already designed to delete the entire row. Is it not doing that for you? Is the value "X1" within your range or can it be anywhere on the sheet? I also noticed a typo in my code: Resize(, 5) should read Resize(, 56).

  6. #6
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    178

    Re: If selection contains any value then

    Hi,

    The X1 is within range. After correction that you gave me your code works well.
    Somehow the code works even if I delete it manualy. I am new at VBA so I got a lot to learn

    Thank you very much for your help.

    All the best.
    B.

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,777

    Re: If selection contains any value then

    You are very welcome.

+ 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. Replies: 2
    Last Post: 12-10-2014, 12:42 AM
  2. Replies: 1
    Last Post: 04-01-2014, 08:10 AM
  3. Replies: 2
    Last Post: 10-07-2013, 11:06 AM
  4. Replies: 3
    Last Post: 07-31-2013, 11:53 AM
  5. [SOLVED] Range(Selection, Selection.End(xlDown)).Select goes to 65536 instead of last filled row
    By looney in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-12-2013, 10:51 AM
  6. Replies: 1
    Last Post: 06-03-2013, 06:30 AM
  7. Multiple selection criteria, which formula? .. and selection based on unique numbers
    By FalkirkJim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2012, 05:22 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