The VB code
ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible)
will return the range of cells that is currently visible in the window. The .SpecialCells is to eliminate those rows that would be in the window, but have been hidden.
This macro
Sub SelectWindow()
ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Select
End Sub
will select that.
This macro will copy the values (equivilant to Copy/PasteSpecialValues) in that range to the same range on "sheet2"
Sub copyWindowValues()
Dim xRay As Range
Set xRay = ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible)
xRay.Parent.Parent.Sheets("sheet2").Range(xRay.Address).Value = xRay.Value
End Sub
This one copies formulas (equivilant to Copy/Paste)
Sub copyWindowToTwo()
Dim xRay As Range
Set xRay = ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible)
xRay.Parent.Parent.Sheets("sheet2").Range(xRay.Address).Formula = xRay.Formula
End Sub
Bookmarks