+ Reply to Thread
Results 1 to 11 of 11

To find the first and last row of a filtered range

  1. #1
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    To find the first and last row of a filtered range

    Hi,

    Im having problems with the following activity.
    I want to filter a column and then fill another column (only with header) with ("Yes") all the way down.

    For doing that, I would like to count how many rows are in the visible column, to estimate the last visible row.

    Once I got that, I would like that my code will work:

    LastRow=Range ("D" & Rows.Count).End(xlUp).Row -1 (headers)

    Range("E2:E & LastRow").SpecialCells(xlCellsTypeVisible).Value = "Yes"

    Could you please help me with that?

    Thanks in advance

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: To find the first and last row of a filtered range

    What are the two Columns and what are the filter criteria...See Top Yellow banner regarding sample file upload and explain in detail what you want to achieve...

    This will give you an idea though...No need for lastrow...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 05-21-2021 at 10:13 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: To find the first and last row of a filtered range

    This will count visible rows

    Please Login or Register  to view this content.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  4. #4
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    Re: To find the first and last row of a filtered range

    Hi again,

    Thanks for your explanation,

    I attach a file of what I exactly need.
    I have to filter the customer column by the customer e, f and g. Then I need a macro to writ Yes in all of these fields. For the filter I used an array as a criteria to put all the names in one go.

    Thanks again,
    Attached Files Attached Files

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: To find the first and last row of a filtered range

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: To find the first and last row of a filtered range

    Macro code

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    Re: To find the first and last row of a filtered range

    Hi Sintek,

    I wanted to thank for your help, I was able to continue with macros.
    However I thought it already worked smoothley until I encounter a minor problem.
    I need to sort a column(17) that contains numbers, from 30 to +121, and filter between intervals of numbers. Then, I have to write a value in the other column.

    For example, if I sort between >=31 and <=60 and then I have to write in another column the letter E. Then, I have to unsort, put the filters again and find the next interval of numbers >=61 and <=90 and write a letter D. I have to repeat that process until I got all these values.

    The problem that I encounter is that the macro ignore the first intervals and I only get the column18 filled by 91-120 even if the column 17 have smaller numbers like 89, 40, 30.... It seems to work only when i filter with just all numbers greater than 121. So I assume Im doing something wrong when setting the filter between two numbers.



    With Cells(1).CurrentRegion

    .AutoFilter 5, ""
    .AutoFilter 17, ">=31"
    .AutoFilter 17, "<=60"
    .Offset(1).Resize(.Rows.Count - 1).Columns(18).Value = "31-60"
    .Offset(1).Resize(.Rows.Count - 1).Columns(19).Value = "E"
    .AutoFilter


    .AutoFilter 5, ""
    .AutoFilter 17, ">=61"
    .AutoFilter 17, "<=90"
    .Offset(1).Resize(.Rows.Count - 1).Columns(18).Value = "61-90"
    .Offset(1).Resize(.Rows.Count - 1).Columns(19).Value = "D"
    .AutoFilter


    .AutoFilter 5, ""
    .AutoFilter 17, ">=91"
    .AutoFilter 17, "<=120"
    .Offset(1).Resize(.Rows.Count - 1).Columns(18).Value = "91-120"
    .Offset(1).Resize(.Rows.Count - 1).Columns(19).Value = "C"
    .AutoFilter


    .AutoFilter 5, ""
    .AutoFilter 17, ">=121"
    .Offset(1).Resize(.Rows.Count - 1).Columns(18).Value = "121+"
    .Offset(1).Resize(.Rows.Count - 1).Columns(19).Value = "B"
    .AutoFilter
    End With


    I appreciate a lot your help,
    Kind regards

  8. #8
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    Re: To find the first and last row of a filtered range

    Additionally I noticed that the code runs well separately, but doesnt work if I dont put and end with between all the conditions. But this is the only issue i encounter and I would like to mark the thread as completed.

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: To find the first and last row of a filtered range

    Your post 7 code has no bearing on your previous requirements????
    Anyway, there is a much more simplistic approach to what you are trying to achieve in Post 7...I can only assist if you upload a sample file with data pertaining to these filters...

  10. #10
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    Re: To find the first and last row of a filtered range

    Hey there,
    I managed to solve the problem, I just put there the operator xland and it worked. But you said that there is a more simplistic approach for that case. I would like to know how you do it.
    I attach you the file:

    Thanks for the help,
    Attached Files Attached Files

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: To find the first and last row of a filtered range

    Please Login or Register  to view this content.
    Last edited by sintek; 05-24-2021 at 12:49 PM.

+ 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. VBA find last row copy range - filtered data
    By muss1210 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2019, 09:41 AM
  2. Copy filtered data into filtered range in a separate sheet
    By vikas.trades25 in forum Excel General
    Replies: 1
    Last Post: 02-07-2019, 04:04 AM
  3. Find average of last 24 hrs data from a filtered range based on a criteria
    By styldude in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-18-2017, 05:18 AM
  4. Replies: 3
    Last Post: 05-07-2017, 02:53 PM
  5. Copy filtered Range, Remove Filter, Find 1st Empty Cell from the bottom, Paste VBA
    By intervals in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2016, 10:48 PM
  6. Replies: 3
    Last Post: 05-16-2012, 05:12 AM
  7. Find the nth largest value in a filtered range
    By digita in forum Excel General
    Replies: 2
    Last Post: 09-07-2011, 02:34 AM

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