andydtaylor
Active Member
- Joined
- Feb 15, 2007
- Messages
- 360
- Office Version
- 2016
Hi,
Would someone be willing to eyeball my code below and advise why it is failing at the line:
".Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete"?
What I find confusing is:
1. There is no sheet protection
2. The table headers are not selected
3. Changing the "Delete" method to "Select" works without issue.
I must apologise because I am somewhat out of practice with VBA as the Power Query/Pivot tools mitigate its need. Ironically this code is to work around a bug I have found with Power Query in the ancient 32 bit excel 2010 / 4-year old Power Query add-in I am having to use!
Thanks,
Andrew
Would someone be willing to eyeball my code below and advise why it is failing at the line:
".Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete"?
What I find confusing is:
1. There is no sheet protection
2. The table headers are not selected
3. Changing the "Delete" method to "Select" works without issue.
I must apologise because I am somewhat out of practice with VBA as the Power Query/Pivot tools mitigate its need. Ironically this code is to work around a bug I have found with Power Query in the ancient 32 bit excel 2010 / 4-year old Power Query add-in I am having to use!
Thanks,
Andrew
Code:
Sub trial_code()
Dim BU_Selction As Variant
Dim Target_BU As String
Dim target_range As Range
Dim source_tables() As Variant
Dim source_table_BU_Pos() As Variant
Dim xlCalc As XlCalculation
Dim lCol As Long
'Record selected BU
BU_Selction = Worksheets("Config_BU").ListObjects("i_selected_BU").DataBodyRange.Value
Target_BU = BU_Selction(1, 1)
' Define table names and columns containing BU description for each table to be trimmed
source_tables = Array("o_Final", "Final_Output")
source_table_BU_Pos = Array(97, 71)
'Store current Calculation then switch to manual.
'Turn off events and screen updating
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
For n = 1 To 1
Set target_range = ActiveSheet.ListObjects(source_tables(n)).Range
lCol = source_table_BU_Pos(n)
With target_range
.AutoFilter Field:=lCol, Criteria1:="<>", Operator:=xlAnd, Criteria2:="<>" & Target_BU
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
Next n
'Turn calcs etc back on
With Application
.Calculation = xlCalc
.EnableEvents = True
.ScreenUpdating = True
End With
On Error GoTo 0
End Sub