+ Reply to Thread
Results 1 to 9 of 9

iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

Hybrid View

  1. #1
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Post iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    Hi,

    My problem is that now that I have added a filter there are only 3 visible cell in the range, but "LastRow" is echoing 97, which is correct because that is where the last cell is, but I dont want to iterate through all of the hidden rows till I get to 97.

    Could someone tell me how I need to structure my current ForLoop:
    Dim LastRow As Integer
    LastRow = ActiveSheet.Cells(Rows.Count, "Z").End(xlUp).Row 
    
    Dim iCount As Integer
    '        For iCount = 10 To LastRow
    So that I could use this:
    Dim v As Range 'http://www.ozgrid.com/forum/showthread.php?t=15629&p=79287#post79287
        Set v = Range("A2:G" & Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Cells 
        MsgBox "The cells are " & v.Address
    Im lost & I have been on this all day. Im wish I came here & asked 1st thing this morning. I wasted a whole day #facePalm#


    TIA

    ~Note~
    This is how I was gonna do my Range I tested it & it works. I just dont know how to put it all togehter with a ForLoop.
    ActiveSheet.Range(Cells(10, 26), Cells(LastRow, 26)).SpecialCells(xlCellTypeVisible).Cells
    Last edited by dlow; 03-04-2015 at 07:23 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    One way:

    Sub dl()
      Dim wks           As Worksheet
      Dim rVis          As Range
      Dim rRow          As Range
    
      Set wks = ActiveSheet
      Set rVis = wks.AutoFilter.Range
    
      If rVis.Rows.Count > 1 Then
        Set rVis = rVis.Offset(1).Resize(rVis.Rows.Count - 1)
        Set rVis = rVis.SpecialCells(xlCellTypeVisible)
    
        For Each rRow In rVis.Rows
          ' carry on ...
        Next rRow
      Else
        MsgBox "No visible cells"
      End If
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    Hi & Thx for the lightnig fast reply & your help.
    Also too, thx for helping so many others, & sharing your knowledge. You' ve saved my bacon more times than you know.
    Last edited by dlow; 03-04-2015 at 07:36 PM.

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    @shg, you are truly first class. I made a similar solution, but you were too quick... Nice work!

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    @ dlow

    You're welcome.

    @ berlan

    That's very kind of you, but I think it's not real robust and will require some tweaks. I don't have much occasion to code around filters.

  6. #6
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    Its really quite good. JMHO
    Option Explicit 'Courtesy of: shg _
    http://www.excelforum.com/excel-programming-vba-macros/1070208-iterate-through-specialcells-xlcelltypevisible-row-range-address.html#post4006324
    Sub Filter_Lynx_O() 
    Dim wks As Worksheet: Set wks = ActiveSheet
    Dim rVis As Range: Set rVis = wks.AutoFilter.Range
    Dim rRow As Range
            If rVis.Rows.Count > 1 Then
              Set rVis = rVis.Offset(1).Resize(rVis.Rows.Count - 1)
              Set rVis = rVis.SpecialCells(xlCellTypeVisible)
                  For Each rRow In rVis.Rows
                      Debug.Print rRow ' carry on ...
                  Next rRow
            Else
              MsgBox "No visible cells"
        End If: Set wks = Nothing: Set rVis = Nothing: Set rRow = Nothing
    End Sub
    Last edited by dlow; 03-04-2015 at 10:28 PM.

  7. #7
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    Doh!!!,
    I forgot that I was also using lastRow+/-1 for some stuff to jump around; Im baffled how I could do that. Would it be a nested forLoop or is there a cleaner way?
    Im searching ATM & thats what it looks like, but Im just asking before I spin my wheels for a few hours.

    In my earlier research I came across some .Subtotal code, I wonder if that might be a better solution. lol I dont even know if it will work with my visible cell issue. #shrug#
    Im gonna be trying to find my way outta this paperbag, if anyone has some insights I would be grateful. TIA

  8. #8
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    Hi, well it doesnt seem as though I need to add another loop.

    So how can I get the next up coming "X" row# without messing up my loop?

    or could my forLoop release 2 range/rows @ 1 time

    ~Update~

    I think I might have it. [Debug.Print rRow_i.Offset(1)]

    I need to test with a larger dataSet though, right now I only have 3 Cell in this sheet.
    Maņana
    Last edited by dlow; 03-05-2015 at 03:03 AM.

  9. #9
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: iterate through SpecialCells(xlCellTypeVisible) Row#, Range.Address

    Huh....
    I cant edit my post, but yeah anyway that was excactly what I needed. "Offset" yeeeesssss........ ready to rock

+ 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 Range.SpecialCells( xlCellTypeVisible ) not working as a UDF
    By dwk49 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2012, 05:29 AM
  2. Resize Range SpecialCells xlCellTypeVisible
    By goss in forum Excel General
    Replies: 1
    Last Post: 07-13-2012, 02:13 PM
  3. Count only SpecialCells(xlCellTypeVisible) with a certain .Value
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-21-2012, 10:19 PM
  4. Cut & Paste - AutoFilter SpecialCells(xlCellTypeVisible)
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-19-2011, 05:28 PM
  5. specialcells(xlcelltypevisible): same code, different results?
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-12-2006, 12:12 PM

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