Results 1 to 2 of 2

Thread: Not able to address vba in the first visible cell in a Column after filtering in Excel

  1. #1
    Join Date
    Jan 2012
    Posts
    26

    Not able to address vba in the first visible cell in a Column after filtering in Excel

    Having difficulty to determine how to address in VBA the first visible cell in Column "D" after the FilterCriteria changes.
    Partial code is as follows:
    Code:
    Set Filter1 = Sheets("Constants Input").Range("A1:F" & _
    Cells(Rows.Count, "D").End(xlUp).Row)
    Filter1.AutoFilter Field:=2, Criteria1:="<>"
    Filter1.AutoFilter Field:=4, Criteria1:="=" & FilterCriteria
    up to this point all is well
    Code:
    Set Filter2 = Nothing
    Set Filter2 = Filter1.SpecialCells(xlCellTypeVisible)
    'I thought that (after) Filter2 the Visible cells would be
    ' reset which they are on the screen
    myCell.Offset(0, 3).Formula = Filter2.Range("E2").Formula
    I thought that after filtering Filter1 that I could Set Filter2 (visable cells) and that Filter1.Range("E2").Formula and Filter2.Range("E2").Formula would be different
    but they are the same. In short, I want all visible cells after filtering in Column E to have exactly the same formula as in the first visible cell in Column E each time that the

    FilterCriteria changes. What happens is that all visible cell formulas are the same as the very first cell in E irrespective of the FilterCriteria. I need to know how in VBA to

    address that first cell in Column E; AFTER each FilterCriteria changes.

  2. #2
    Join Date
    Jun 2011
    Posts
    635

    Re: Not able to address vba in the first visible cell in a Column after filtering in Excel

    Maybe you could use something like the below code:
    Code:
    with worksheets("constants input")
    with .autofilter.range
    if .columns(1).cells.specialcells(xlcelltypevisible). cells.count = 1 then
    'do nothing, only the header is visible
    else
    'go to column 5 (E) and come down a row and subtract a row to
    'ignore the header
    set myvrng = .columns(5).resize(.rows.count,1).offset(1,0) _
    .cells.specialcells(xlcelltypevisible)
    myvrng.formular1c1 = myvrng.cells(1).formular1c1
    end if
    end with
    myVRng is the visible cells in column 5 of the filtered range. myVRng.cells(1) is the first cell in that visible range.

Similar Threads

  1. Replies: 1
    Last Post: 10-04-2012, 11:16 PM
  2. Want to paste data only in visible cell of Microsoft Excel
    By FullTimepass in forum MS Office Support
    Replies: 2
    Last Post: 16-02-2012, 07:21 PM
  3. Replies: 2
    Last Post: 03-02-2012, 07:28 PM
  4. Replies: 3
    Last Post: 09-12-2009, 01:11 PM
  5. Text not visible in cell only in Formula Bar (excel 2003)
    By NavinS in forum MS Office Support
    Replies: 1
    Last Post: 14-02-2008, 03:32 AM

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
  •  
Page generated in 1,713,298,201.34698 seconds with 18 queries