I'm trying to auto-copy a row from a master spreadsheet to another spreadsheet. This should occur when the input value in the master is equal to X.
So if X is entered into Column A in the master, then auto-copy to separate spreadsheet (let's call it X). Basically Sheet X should always contain an exact copy of all the rows in master where Column A = X.
I'm not sure if this would affect the auto-copy but the master sheet contains a script that hides/unhides Columns. So if X is entered into Column A in the master sheet then Column B,C will be hidden and D,E,F will be shown.
An example of what I'm trying to achieve is shown below:
Master Sheet contains this info. But if X is entered into Column A only D,E,F will be visible
A B C D E F
X 4 5 6
Y 1 2 3 4 5
X 1 2 3
X Sheet:
A D E F
X 4 5 6
X 1 2 3
This is what I've attempted
Sub FilterAndCopy()
Dim sht1 As Worksheet, sht2 As Worksheet
Set sht1 = Sheets("Master")
Set sht2 = Sheets("X")
Intersect(sht2.UsedRange, sht2.Rows("2:" & Rows.Count)).ClearContents
sht1.Cells(1, 1).CurrentRegion.AutoFilter
sht1.Cells(1, 1).CurrentRegion.AutoFilter 1, "X"
sht1.Cells(1, 1).CurrentRegion.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Copy sht2.Cells(2, 1)
sht1.Cells(1, 1).CurrentRegion.AutoFilter
End Sub
But it returns an Error:
Microsoft Visual Basic
Object variable with block variable not set
IntersectreturnsNothing, what object reference is.ClearContentsinvoked against?