Using VBA in Excel to get values from cell to VBA, so I can load new data to my cube

Exceldoktor

New Member
Joined
Oct 20, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. 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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you're only trying to pass the "C104 - Patrick Strzesnicki" this code should work. However I'm not sure where you're getting the C102 - Olaf Grolle from.

VBA Code:
Dim SVAL As String
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



End Sub

Sub Macro3()
'
' Macro3 Macro
'

'
ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array ("[Sales Representative].[Sales Rep].&[" & SVAL & "]")
ActiveWorkbook.SlicerCaches("Slicer_Sales_Rep").VisibleSlicerItemsList = Array ( "[Sales Representative].[Sales Rep].&[C102 - Olaf Grolle]")
End Sub
 
Upvote 0
Hi,
The Purpose of my macro is to walk through a list of names and for each of these persons to run the macro.
That is where the next name come into my macro.
We need to change the slicer and thereby update a number of Pivottables. Based on those updated slicers we will open a file, and the combination of the values of the pivottables and the values in the files, we will read input to a cube.

I believe that the rest of the VBA is within my knowledge. If you are sure that it can walk through a list of names , then I will test that tomorrow, and put in the rest of the code

Best regards
Jørgen
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top