+ Reply to Thread
Results 1 to 9 of 9

Wont select the row intended

  1. #1
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Question Wont select the row intended

    Hey there,

    I have created a macro to delete any row which has a date older than the date specified by the user. However for some odd reason, when the macro finds a row which has an older date, it doesnt select that date and ends up selecting a completely different row and deletes that.

    My macro code is shown below and I have attached my spreadsheet. If anyone has a clue as to why its selecting the wrong row then that would be great as I am quite honestly baffled!

    Please Login or Register  to view this content.
    For some odd reason I keep getting a database error when I try to upload my spreadsheet but I'll try again once I post this thread.

    Thanks,

    Jag
    Last edited by therealjag; 02-23-2010 at 11:42 AM.

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Wont select the row intended

    Hi,
    I don't know if this will solve your problem, but anyway if you loop trough the rows with data and delete a row when condition is met, you should start from the last row and use step -1.
    Buran
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Re: Wont select the row intended

    Hey Buran,

    Do you have an example of what you are meaning? I tried the line:

    Please Login or Register  to view this content.
    But it doesnt seem to be working?

    Cheers,

    Jag

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Wont select the row intended

    Here is the code

    Please Login or Register  to view this content.
    Please note also that using .UsedRange.Rows.Count may cause problems if you have empty rows. For example if you have one or more empty rows (i.e rows 1 is empty and your data are in rows 2 to 6) then .UsedRange.Rows.Count will return 5 and you will not check the last row (6). Hope this is not the case in your workbook.

  5. #5
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Re: Wont select the row intended

    Hey nah luckily my sheet doesn't contain empty rows but it still doesnt select the correct row. It does however return the correct row but ends up deleting row 21 for some odd reason! :S

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Wont select the row intended

    Oh, I should have noticed that the first time
    I think the problem is in this line

    Please Login or Register  to view this content.
    change it to this

    Please Login or Register  to view this content.
    PS, changed the line to fix - you should change the line where you delete the row
    Last edited by buran; 02-23-2010 at 11:26 AM.

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Wont select the row intended

    By the way, you don't need to select the row. i.e.
    this line is not needed at all:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Re: Wont select the row intended

    Mate you're a genius. Absolute.......genius!

  9. #9
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Wont select the row intended

    I'm glad that was able to help. Don't forget to mark the thread solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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