+ Reply to Thread
Results 1 to 29 of 29

Lastrow definition problem

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Lastrow definition problem

    Hello, so far, I've been using this to take into account all the data until the last non-blank data from a column:

    Please Login or Register  to view this content.
    Now, I'd like to define lastrow from a column to a specific value. For instance, all the data until the word "blank" comes up.

    So if I had from V52:

    a
    b
    c
    d
    e
    f
    g
    blank
    blank
    blank

    Last row would stop at "g". Is that possible?

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Lastrow definition problem

    Try

    Please Login or Register  to view this content.

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    YounesB3,

    If those values started V52 and went to V61 and you wanted the row number 58 which is the row "g" is in, you could use the following:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: Lastrow definition problem

    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  5. #5
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    @tigeravatar

    I guess it would have worked, but I haven't had the opportunity to try it because my plan didn't work lol...

    Let me explain: I apply a filter in column W. I need to copy data from column U to column C (at the end where the first blank cell appears.

    This is the code I use so far (i replaced with "?" all characters which could be confidential:

    Please Login or Register  to view this content.
    I highlighted in yellow the thing which needs to be changed..

    At first, I tried to find a blank cell, but because of the filter, it didn't work. For instance, if I had lines 167, 289, 384 & 487 showing (because of the filter) and the last filled line was 550, when I did the find "", it didn't go to line 551, but instead changed column and went to the first empty cell.

    Then, I added the formula : =if(isblank(A??), "blank", "") from line 550 to something like 1000 or 1250. That didn't work either because when I apply the filter, the last line shows as 1000 (or 1250) instead of 550.

    I'm not sure if I'm being clear or not. If you need more explaination, please advise.

    Any ideas on how I could do the copying from U to C?

    Cross-post: http://www.msofficeforums.com/excel-...html#post40618
    Last edited by Cutter; 10-15-2012 at 05:04 PM. Reason: Removed whole post quote

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    Don't you just want to copy the results after the filter is applied? Is there any reason you don't want that?

  7. #7
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    Here's a quick step of what I do manually (and want to automate).

    - I apply the filter in column W.
    - Results appear in column U.
    - I take the results from U and paste it at the END of column C (first blank cell).

    I can't do the last one in a macro. Note the line number always changes due to constant updating.

    As explained, I already tried searching for "", but for some reason it doesn't work.
    I also tried to input "blank" from the first blank cell to X, but if I do that and apply the filter, all the words "blank" are not going to show up (so I can't search for the word "blank" with the macro).

    Thanks for any help you can provide!
    Last edited by Cutter; 10-15-2012 at 05:03 PM. Reason: Removed whole post quote

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    Something like this?
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    This pratically works! I just had to modify ".AutoFilter 1" with ".AutoFilter 23" (for column W).

    The only fix which I don't know how to do is, it takes the whole column U and past is as values. The thing I didn't mention in previous post is that the filters are applied from line 51 and I would like to take the data from line 52 (in column U) to the end of column U. How do I modify the macro?

    Also, could you explain a bit what you did in the macro so I understand more? :P

    Thanks a lot!
    Last edited by Cutter; 10-15-2012 at 05:01 PM. Reason: Removed whole post quote

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    YounesB3,

    Can you post the code you're using?

  11. #11
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    The same as before, but I replaced your code with the old one I had:

    Please Login or Register  to view this content.
    Last edited by Cutter; 10-15-2012 at 05:03 PM. Reason: Removed whole post quote

  12. #12
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    Honestly I would be very surprised if that code doesn't error on the .AutoFilter 23, "0ADD ???" line.

    I used 'With Intersect(ActiveSheet.UsedRange, Columns("W"))' to explicitly only "select" column W. Therefore, there is only 1 field, which is why it is .AutoFilter 1 instead of .AutoFilter 23.

    If you need the filter applied starting at row 51 so that it only grabs data from row 52 down, just update the With line:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    When I use it with 1 instead of 23, it applies the filter in column A.

    Except from that, with the modification you applied, it now works! Thanks a lot!

    Can you explain a bit the vb code you used?
    Last edited by Cutter; 10-15-2012 at 05:02 PM. Reason: Removed whole post quote

  14. #14
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    Thanks a lot!
    Last edited by Cutter; 10-15-2012 at 05:02 PM. Reason: Removed whole post quote

  16. #16
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    @tigeravatar

    I have one last problem (I hope). Somehow, when I filter to "0ADD ???", it doesn't only shows "0ADD ???" for some reasons.

    Example of what it sometimes do:

    Column U Column V Column W
    ???1 ???A 0ADD ???
    ???2 ???B 0ADD ???
    ???3 ???C 0ADD ???
    ???4 ???D 0ADD ???
    ???5 ???E 0ADD ???
    ???6 ???%
    ???7 0ADD ???
    ???8 ???@
    ???9 ???&
    ???7 0ADD ???
    ???11 ???$

    Now, with the present macro, it would take everything in column U. What I want to do is to take everything in column U when it says column W "0ADD ???". I'm not sure why the filter doesn't work properly...
    Last edited by Cutter; 10-18-2012 at 05:26 PM. Reason: Removed whole post quote

  17. #17
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    When using an autofilter (either manually or through VBA code), the question mark character is considered a wildcard, which is probably why you're getting some results you didn't expect. I was under the impression you wanted to use the wildcard character. Since that is not the case, here is an alternate method using Evaluate() instead of .AutoFilter

    Please Login or Register  to view this content.

    The Evaluate() method is a bit more advanced, but shouldn't use the question mark as a wildcard character.

  18. #18
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    Actually, I'm not using ???, I'm using 3 letters. It's just because I don't want to put anything which I shouldn't be posting

  19. #19
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    If you're filtering for "0ADD XYZ" that shouldn't cause any issues. I'd have to see an example workbook experiencing the problem to diagnose, because I am unable to duplicate the problem with the information that I have.

  20. #20
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    I previously did an example file. You can find it here: Attachment 187313

    Of course, I replaced all the elements which I can't put on the net due to company policies.

    In the example I posted, it doesn't do what I mentionned in the topic. I messed around with the example file and created a file when it does happen: Attachment 187312

    As you can see, the problem occurs when there is more data in column U & W then number of data in column A to Q & V. I'm not sure why though...
    Last edited by Cutter; 10-18-2012 at 05:26 PM. Reason: Removed whole post quote

  21. #21
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    I am unable to view that file. I am at work and cannot get to that site, please use the attach file method provided by this forum.

    To attach a file, click the "Go Advanced" button and then click the paperclip icon to open the Manage Attachments dialog.

  22. #22
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    @tigeravatar

    Oups sorry about that, I didn't see it (the site was actually the only one not blocked over here ;p). The files are now attached.

    Example.xlsx

    Example 2.xlsx
    Last edited by Cutter; 10-18-2012 at 05:25 PM. Reason: Removed whole post quote

  23. #23
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    Ah, the problem was that you already had a filter area applied. I included to remove any filters before applying mine and that seems to have taken care of it:
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    Thank you so much, I'll try that tomorrow with the new data and give you some news! :P
    Last edited by Cutter; 10-17-2012 at 09:32 AM. Reason: Removed whole post quote

  25. #25
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    @tigeravatar
    Everything since to work perfectly now thanks to you!

    I'm not sure if I should start another thread or not, but since it's the same file here it is (cross-posted in mr excel & ms office forums; but none answered in some days):

    So, I had a superb macro working before:

    Please Login or Register  to view this content.
    This would hide rows of 5 different tab in a worksheet between 2 columns. The problem is, I now had to put some formulas to automate the file and the macro doesn't work anymore even if the value in the cell = "". Is it possible to change the above code to work for cells which are either blank or = ""? Right now it only works for blank rows with no formulas at all

    Thanks a lot!
    Last edited by Cutter; 10-18-2012 at 05:24 PM. Reason: Removed whole post quote

  26. #26
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Lastrow definition problem

    This is different enough that it should be a new thread. You'll want to make sure you provide the links to the crossposts also

  27. #27
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    Ok, will do! Thanks!

  28. #28
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Lastrow definition problem

    @ YounesB3

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  29. #29
    Registered User
    Join Date
    09-05-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Lastrow definition problem

    Quote Originally Posted by Cutter View Post
    @ YounesB3

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
    Good to know, thanks.

+ 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