简体   繁体   中英

Excel VBA- Moving Past Hidden Cells in a Filtered Column

I have a code where I need to copy data from filtered cells in Column E to Column A. The filter is done by a loop therefore data is displayed one by one. All I need to do is to directly go down one cell from my active cell but the problem is, I have no idea what cell value is directly below and if I use offset, excel just copies the next hidden cell.

Here is a brief overview of how the macro works:

First Cell is E1(header and active cell) next cell is E102(value I have to copy to A102).

Then a loop activates, first cell is E1 then next cell is E365(copy to A365). and so on...

The next value is also unpredictable therefore I cannot call the value.

I've tried the following code but send keys doesn't seem to work

Cells.Find(What:="Header", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 3).Range("A1").Select

Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys "{DOWN}"

Selection.Copy
ActiveCell.Offset(0, -3).Range("A1").Select
Selection.Paste

Usually you need to work with the Areas property but you have a special case where you only require the second cell.

'assume column E has been filtered
With Worksheets(ActiveSheet.Name)
    With Intersect(.UsedRange, .Range("E:E"))
        With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0)
            .SpecialCells(xlCellTypeVisible)(1).Offset(0, -4) = _
                .SpecialCells(xlCellTypeVisible)(1).Value
        End With
    End With
End With

I don't know why your code says .Offset(0, -3) since column A is a -4 offset from column E.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM