ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 865
- Office Version
- 365
- 2019
- Platform
- Windows
I have a line of code that transfers data over to a tab based off of data in cell A2. When doing so it un-hides my source data, and doesn't re-hide that source data after. I am looking for a way to detect what is hidden before the code runs, run the code, then reapply the hidden rows. Currently I have the below BUT the hidden rows aren't always that range so I am looking for a dynamic approach. Any help is much appreciated
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Sheets("Sheet1") '<--- change data to actual sheet name that holds the source data
If Target.Address(0, 0) <> "A2" Then Exit Sub
Application.EnableEvents = False
[a4].CurrentRegion.Offset(1).Clear
If (Not Target Like "*[!0-9]*") * (Len(Target) = 4) Then
With ws.Range("a1", ws.Cells.SpecialCells(11))
.AutoFilter 18, , 7, Array(0, "1/25/" & Target)
.Copy [a3]
.AutoFilter
End With
'ws.Rows("2:5030").Hidden = True
End If
Application.EnableEvents = True
End Sub