I have a multi-step process with a workbook, that I have hidden rows on. When I get to a second page, I pull some of the info on the first page and it populates a range with all the data I need, with out extra lines. It does this with VBA code that uses "Filter". When I run this VBA code, it makes all the hidden rows on page 1 show again. I've put the code I'm using below, is there a way to do this without messing up the original page formatting/hidden rows?
Thanks!
VBA Code:
Sub GetRTFInfo()
Worksheets("CS INFO SHEET").Range("B2:E1300").ClearContents
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng As Range, rngToCopy As Range
Dim lastRow As Long
'change Sheet1 and Sheet2 to suit
Set ws1 = ThisWorkbook.Worksheets("ADDRESS MATRIX")
Set ws2 = ThisWorkbook.Worksheets("CS INFO SHEET")
With ws1
'assumung that your data stored in column A:B, Sheet1
lastRow = .Cells(.Rows.Count, "AF").End(xlUp).Row
Set rng = .Range("AF13:AI" & lastRow)
'clear all filters
.AutoFilterMode = False
With rng
'apply filter
.AutoFilter Field:=4, Criteria1:="x"
On Error Resume Next
'get only visible rows
Set rngToCopy = .SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
'copy range
If Not rngToCopy Is Nothing Then rngToCopy.Copy
ws2.Range("B2").PasteSpecial Paste:=xlPasteValues
'clear all filters
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Worksheets("CS INFO SHEET").Range("E2:E1300").ClearContents
End Sub
Thanks!