Consulting

Results 1 to 10 of 10

Thread: Find Last Used Cell of Visible Cells

  1. #1

    Find Last Used Cell of Visible Cells

    Provided w/ a tip to use SpecialCells(xlCellTypeVisible) to copy filtered cells, can I use SpecialCells to count rows?

    This does not work, but hopefully illustrates the idea of the desired result.

    lLrwt = Wss2.SpecialCells(xlCellTypeVisible).Cells(Rows.Count, "A").End(xlUp).Row
    Last edited by Aussiebear; 04-20-2023 at 05:29 AM. Reason: Adjusted the code tags
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    lLrwt = Wss2.Columns(1).SpecialCells(xlCellTypeVisible).Cells(Rows.Count, "A").End(xlUp).Row
    Last edited by Aussiebear; 04-20-2023 at 05:30 AM. Reason: Adjusted the code tags
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ACtually, I don't think you even need SpecialCells

    lLrwt = Wss2.Cells(Rows.Count, "A").End(xlUp).Row
    Last edited by Aussiebear; 04-20-2023 at 05:30 AM. Reason: Adjusted the code tags
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    if Wss2 is a single column of the whole unfiltered range then

    Range("A2:A21").SpecialCells(xlCellTypeVisible).Count
    specifically:

    Wss2.SpecialCells(xlCellTypeVisible).Count
    Last edited by Aussiebear; 04-20-2023 at 05:31 AM. Reason: Adjusted the code tags
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Thanks Bob,
    The last used cell on the sheet is in fact 12764, lLrwt reflects this in the Locals window. However, the number of visible rows are 89.
    So what is happening here? Is it not counting and just returning the value of the last row?
    If this is the case how do we alter it to count?
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  6. #6
    Bob-
    I had this exact line prior, and it returns the value of 12764, it does not count the visible rows only, it returns the value of the last visible row.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  7. #7
    This sheet formula returns the count of 89,
    HTML Code:
    =SUBTOTAL(103,C2:C12764)
    Last edited by Aussiebear; 04-20-2023 at 05:32 AM. Reason: Added code tags
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Doug

    If you just want to count based on some criteria why not use something like COUNTIF?

  9. #9
    Norie,
    Sorry, I don't understand your suggestion as it pertains to this issue.
    Maybe COUNTIF will work, but it seems to break rank w/ how the rest of my code is structured.
    I can locate the correct amount of rows if I move my variable line after the last line of SpecialCells. Copy, Highlighted in Red for an easy read. This works because now the code has something it can count on the target worksheet.
    But this in my opinion is a hack method.
    My problem w/ this is that it fixes something that should be handled initially, not on the rebound. Since WsS2, the source worksheet where the visible cells are located, it seems that there should be an easy way to count the visible cells on the Source Sheet and obtain count value at that point.
    It is a matter of trying to write this as smoothly as possible, my method here shows a lack of style and agility.... trying to improve upon this.


    Set WsS = Workbooks("MasterImportSheetWebStore.xls").Sheets("TGFF")
    Set WsS2 = Workbooks("MasterImportSheetWebStore.xls").Sheets("PCCombined_FF")
    Set WsT = Workbooks("MaintImport.xls").Sheets("Record Creator")
    lLrwS = WsS.Cells(Rows.Count, "A").End(xlUp).Row
    'lLrwT = WsS2.Cells(Rows.Count, "A").End(xlUp).Row
    lLrwT = WsS2.Columns(1).SpecialCells(xlCellTypeVisible).Cells(Rows.Count, "A").End(xlUp).Row
    'lLrwT = WsS2.Cells.SpecialCells(xlCellTypeVisible).Cells(Rows.Count, "A").Row
    WsS2.Range("B2").Resize(lLrwS - 1).SpecialCells(xlCellTypeVisible).Copy WsT.Cells(6, "W") 'Record# Cols. B2>>W6
    WsS2.Range("E2").Resize(lLrwS - 1).SpecialCells(xlCellTypeVisible).Copy WsT.Cells(6, "AC") 'Qty. Cols. E2>>AC6
    WsS2.Range("F2").Resize(lLrwS - 1).SpecialCells(xlCellTypeVisible).Copy WsT.Cells(6, "AD") 'Dept. Cols. F2>>AD6
    WsS2.Range("G2").Resize(lLrwS - 1).SpecialCells(xlCellTypeVisible).Copy WsT.Cells(6, "AE") 'Cat. Cols. G2>>AE6
    WsS2.Range("H2").Resize(lLrwS - 1).SpecialCells(xlCellTypeVisible).Copy WsT.Cells(6, "AA") 'Price Cols. H2>>AA6
    lLrwT = WsT.Cells(Rows.Count, "W").End(xlUp).Row
    Last edited by Aussiebear; 04-20-2023 at 05:32 AM. Reason: Adjusted the code tags
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Doug

    You seemed to be asking asked how to count filtered rows.

    Obviously the filter would be based on some criteria I assume, so why not use COUNTIF or a similar formula.

    If the real issue is copying based on some criteria I would suggest another method. eg advanced filter or even a loop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •