I have code that auto-copies specific cells from a master sheet into another sheet. This is achieved when a specific value is entered into Column B.
For the example below, I want to copy all cells where the value in Column B is equal to Faults Raised. The issue I'm having is the master sheet has a separate script that hides/unhides columns based on other various 'values' entered into Column B.
When Faults Raised is entered, Columns B:C, AC:AE, BP are shown. But when I try to auto-copy across only Column B is shown. I can't get C, AC:AE and BP to copy across? What am I doing wrong?
Option Explicit
Sub FilterAndCopy()
Dim sht1 As Worksheet, sht2 As Worksheet
Set sht1 = Sheets("SHIFT LOG")
Set sht2 = Sheets("FAULTS RAISED")
sht2.UsedRange.ClearContents
Dim rng As Range
With sht1.Cells(2, "B").CurrentRegion
.Range("B:BP").EntireColumn.Hidden = False ' unhide columns
.AutoFilter
.AutoFilter 2, "Faults Raised"
.SpecialCells(xlCellTypeVisible).Copy sht2.Cells(6, 2)
.AutoFilter
.Range("C:AA").EntireColumn.Hidden = True ' hide columns
sht2.Range("C:AA").EntireColumn.Delete ' delete 'sht2' columns
.Range("AE:BN").EntireColumn.Hidden = True ' hide columns
sht2.Range("AE:BN").EntireColumn.Delete ' delete 'sht2' columns
End With
End Sub