+ Reply to Thread
Results 1 to 4 of 4

To shorten lengthy if condition

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-13-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    152

    To shorten lengthy if condition

    Please help me to shorten this lengthy condition. Is there any way to write this code simpler?

    If sheets("Filter").cells(5009,428).value="True" AND sheets("Filter").cells(5010,428).value="True" AND sheets("Filter").cells(5011,428).value="True" AND sheets("Filter").cells(5012,428).value="True" AND sheets("Filter").cells(5013,428).value="True" AND sheets("Filter").cells(5014,428).value="True" AND sheets("Filter").cells(5015,428).value="True" Then
    Thanks

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,636

    Re: To shorten lengthy if condition

    Try

    If WorksheetFunction.CountIf(sheets("Filter").Range(sheets("Filter").cells(5009,428), sheets("Filter").cells(5015,428)), True) = 7 Then

  3. #3
    Forum Contributor
    Join Date
    03-13-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    152

    Re: To shorten lengthy if condition

    Thanks zbor, much better than my code. However expected even simpler , I think it is not possible.

    Anyway thanks again. I will use your code.

  4. #4
    Forum Contributor
    Join Date
    03-13-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    152

    Re: To shorten lengthy if condition

    Zbor,

    it throws an error 'Subscript out of range'.

    edited your code like below but it too not works.

    If WorksheetFunction.CountIf(Sheets("Filter").Range("PL5009:PL5015"), True) = 7 Then
    Last edited by gan_xl; 06-19-2015 at 06:11 AM.

+ 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. [SOLVED] VBA, Simplify lengthy if condition
    By gan_xl in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-16-2014, 05:16 AM
  2. Shorten lengthy VBA Code to delete rows of data outside of multiple criteria
    By orenjisoda in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2014, 09:49 PM
  3. Shorten a lengthy code
    By Pyro Form in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-27-2012, 04:51 AM
  4. Lengthy problem - I am in need of help!
    By paultucker79 in forum Excel General
    Replies: 5
    Last Post: 06-20-2006, 05:50 AM

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