
Originally Posted by
p45cal
x = Array(VIL & ItemString,VIL2 & ItemString2,VIL3 & ItemString3)
OK, thank you for helping me out. I wanted to post the entire function in case it might ever help anyone else. I am sure I could clean it up a bit and make it look better but I have spent way too much time already for what this is. I had to use the split function to break the string down into elements to populate the array. I am marking this as solved and moving on with my life.
Sub MoM_Arr()'
' Updates MTD Pivot to show correct dates for Month over Month comparison
'
Dim i As Long
Dim NUMDAYS As Integer
Dim ArrCnt As Integer
Dim VIL As Variant
Dim ItemString As Variant
Dim pvtItems As Variant
Dim CurYear As String
Dim CompYear As String
Dim CurMonth As String
Dim CompMonth As String
Dim MyDay As String
'Populate Date Variables
NUMDAYS = ActiveWorkbook.Worksheets("Tools").Range("NUMDAYS")
CurMonth = ActiveWorkbook.Worksheets("Tools").Range("MAXMONTH")
CompMonth = ActiveWorkbook.Worksheets("Tools").Range("COMPMONTH")
CurYear = ActiveWorkbook.Worksheets("Tools").Range("MAXYEAR")
CompYear = ActiveWorkbook.Worksheets("Tools").Range("COMPYEAR")
'Create the strings for the array
For i = 1 To NUMDAYS
Select Case i
Case Is = NUMDAYS
VIL = VIL & "" & Chr(44) & Chr(32)
Case Else
VIL = VIL & "" & Chr(44) & Chr(32)
End Select
Next i
For i = 1 To NUMDAYS
Select Case i
Case Is < 10
MyDay = CStr(0 & i)
Case Else
MyDay = CStr(i)
End Select
Select Case Len(CurMonth)
Case Is = 1
CurMonth = CStr(0 & CurMonth)
Case Else
CurMonth = CStr(CurMonth)
End Select
ItemString = ItemString & "[Report Date].[Date].[Day].&[" & CurYear & "-" & CurMonth & "-" & MyDay & "T00:00:00]" & Chr(44) & Chr(32)
Select Case Len(CompMonth)
Case Is = 1
CompMonth = CStr(0 & CompMonth)
Case Else
CompMonth = CStr(CompMonth)
End Select
ItemString = ItemString & "[Report Date].[Date].[Day].&[" & CompYear & "-" & CompMonth & "-" & MyDay & "T00:00:00]"
Select Case i
Case Is = NUMDAYS
'Dont add a delimiter at the end, this is the last element
Case Else
ItemString = ItemString & Chr(44) & Chr(32)
Debug.Print ItemString
End Select
Next i
'Combine the array strings
ItemString = VIL & ItemString
'Populate the array
pvtItems = Split(ItemString, ", ")
'Update the pivot table to show the correct dates
ActiveWorkbook.Sheets("MTD").PivotTables("PivotTable4").PivotFields("[Report Date].[Date].[Day]").VisibleItemsList = Array(pvtItems)
End Sub