+ Reply to Thread
Results 1 to 3 of 3

Problem IF statement

  1. #1
    Registered User
    Join Date
    11-21-2005
    Posts
    46

    Question Problem IF statement

    Dear all,

    I have the following VBA code (shown below) which activates a row delete loop if one or more conditions are met. However, I only want to activate the loop if for a given row in column F (column 6), the value is greater than 10000. The code as it stands is:

    Please Login or Register  to view this content.
    This version appears to work.

    My attempt to include the previously mentioned extension is as follows:

    Please Login or Register  to view this content.
    However, although I get no errors, the code appears to do nothing (i.e. doesn't delete any rows), even though there are cells of greater value than 10000 in column F.

    Would someone be able to provide some advice as to what I'm doing wrong please?

    Thanks
    smurray444

  2. #2
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    I think your probelm is here:

    Please Login or Register  to view this content.
    it should be:

    Please Login or Register  to view this content.
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  3. #3
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by smurray444
    Dear all,

    I have the following VBA code (shown below) which activates a row delete loop if one or more conditions are met. However, I only want to activate the loop if for a given row in column F (column 6), the value is greater than 10000. The code as it stands is:

    Please Login or Register  to view this content.
    This version appears to work.

    My attempt to include the previously mentioned extension is as follows:

    Please Login or Register  to view this content.
    However, although I get no errors, the code appears to do nothing (i.e. doesn't delete any rows), even though there are cells of greater value than 10000 in column F.

    Would someone be able to provide some advice as to what I'm doing wrong please?

    Thanks
    smurray444
    There are two issues with your macro.
    1. You perhaps want lRow to be the last row of the used range. But you are not really achieving this if your used range does not start from the first row. To explain, suppose the used range has 10 rows and starts from say row 6 ( ie from row 6 to row 15 ). lRows = ActiveSheet.UsedRange.Rows.Count will give lRow = 10 but your last row of the region is 15. To get absolute address of the last row lRow should really be Activesheet.Usedrange.Row+Activesheet.Usedrange.Rows.Count-1

    2. The way you have written the macro, the loop executes only if the last row has more than 10000 in column F. If it is not then the loop does not get executed at all. The macro checks if in the last row, col F has more than 10000 and if it is true then deletes those rows which have more than 1.5 in F.
    Is that what you want? If not and if you want to delete all the rows in the region with value more than 10000 in F then why don't you just replace 1.5 with 10000 in your first macro?

    A V Veerkar
    Last edited by avveerkar; 08-31-2007 at 11:20 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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