Exceldoktor
New Member
- Joined
- Oct 20, 2020
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
- MacOS
- Mobile
- Web
Hi everyone
We have to read data from Excelfiles to our datawarehouse, and we are using a slicer in Excel to select next file to read to our datawarehouse.
Our Slicer is created from a Power pivottable that is connected to our datawarehouse.
I have created a macro (Macro3) that is recorded and that works fine, but when I try to put in a variable to be able to use for next statement, my VBA does not work, no matter how I put in the variable inside my Macro. I have tried several suggestions found on the internet. The Issue seems to be my cubeformula getting the value of the variable.
My macro, that should get the value of the variable is Macro1 and my variable is called SVAL.
I hope that some of you have experience in the cube formulaes from the Power BI datasets.
Sub Macro1()
'
' Macro1 Macro
'
SVAL = "C104 - Patrick"
'
With ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep")
.ClearManualFilter
For Each oSlicerItem In .SlicerItems
If oSlicerItem.Name = SVAL Then
oSlicerItem.Selected = True
Else
oSlicerItem.Selected = False
End If
Next oSlicerItem
End With
' ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array _
' ( _
' "[Sales Representative].[Sales Rep].&[C104 - Patrick]")
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array _
("[Sales Representative].[Sales Rep].&[C104 - Patrick Strzesnicki]")
ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array _
( _
"[Sales Representative].[Sales Rep].&[C102 - Olaf Grolle]")
End Sub
------------------------------
Jørgen Wulff Rasmussen
Partner
Exceldoktor
Taastrup
23732009
We have to read data from Excelfiles to our datawarehouse, and we are using a slicer in Excel to select next file to read to our datawarehouse.
Our Slicer is created from a Power pivottable that is connected to our datawarehouse.
I have created a macro (Macro3) that is recorded and that works fine, but when I try to put in a variable to be able to use for next statement, my VBA does not work, no matter how I put in the variable inside my Macro. I have tried several suggestions found on the internet. The Issue seems to be my cubeformula getting the value of the variable.
My macro, that should get the value of the variable is Macro1 and my variable is called SVAL.
I hope that some of you have experience in the cube formulaes from the Power BI datasets.
Sub Macro1()
'
' Macro1 Macro
'
SVAL = "C104 - Patrick"
'
With ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep")
.ClearManualFilter
For Each oSlicerItem In .SlicerItems
If oSlicerItem.Name = SVAL Then
oSlicerItem.Selected = True
Else
oSlicerItem.Selected = False
End If
Next oSlicerItem
End With
' ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array _
' ( _
' "[Sales Representative].[Sales Rep].&[C104 - Patrick]")
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array _
("[Sales Representative].[Sales Rep].&[C104 - Patrick Strzesnicki]")
ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array _
( _
"[Sales Representative].[Sales Rep].&[C102 - Olaf Grolle]")
End Sub
------------------------------
Jørgen Wulff Rasmussen
Partner
Exceldoktor
Taastrup
23732009