Beneindias
Board Regular
- Joined
- Jun 21, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi to all,
Here I am again to bring my problems with vba.
I have a workbook where I have a few sheets, that all have one table and one pivot table.
To update the data on the pivot table, I have this code, that runs when I change the column "Valor s/ Iva" on the table:
When I run this macro, I get this error:
run-time error '1004': Method 'Intersect' of 'object '_Global' failed
On this line:
If Not Intersect(Target, Range(tblColName)) Is Nothing Then
I have added those two MsgBox, and the first on ("Intersected") shows, but not the second one.
Although I get the error, the data still updates on the pivot tables
Thank you all
Here I am again to bring my problems with vba.
I have a workbook where I have a few sheets, that all have one table and one pivot table.
To update the data on the pivot table, I have this code, that runs when I change the column "Valor s/ Iva" on the table:
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim tbl As ListObject
Dim tblName As String
Dim tblColName As String
For Each tbl In ActiveSheet.ListObjects
'Application.ScreenUpdating = False
'Table name
tblName = tbl.Name
'Column name
tblColName = tblName & "[Valor s/ Iva]"
If Not Intersect(Target, Range(tblColName)) Is Nothing Then
'Refreshes workbook pivot tables
MsgBox "Intersected"
ThisWorkbook.RefreshAll
MsgBox "Updated"
End If
'Application.ScreenUpdating = True
Next tbl
End Sub
When I run this macro, I get this error:
run-time error '1004': Method 'Intersect' of 'object '_Global' failed
On this line:
If Not Intersect(Target, Range(tblColName)) Is Nothing Then
I have added those two MsgBox, and the first on ("Intersected") shows, but not the second one.
Although I get the error, the data still updates on the pivot tables
Thank you all