cancel
Showing results for 
Search instead for 
Did you mean: 

Filter date range in VBA

Hello,

I've been looking all over Internet and couldn't find a solution to my problem. I really feel I'm doing it right though...

I'd like that each time I update my report via macro it shows the data from the last 2 months. These are set in a "Filter by range" on Calendar Day (0CALDAY). To do this I have a function that gives me the date of yesterday and the date of minus 61 days and values get concatenated and returned as a filter value. However, when checking after the macro has run I see that nothing has changed in my filters. Any thoughts?

Thanks in advance.

Best regards,

Private Sub RefreshAnalysis()
    With Application
        .Run("SAPExecuteCommand", "Refresh", "DS_5"

        'freeze Analysis for variables & filters
        .Run "SAPSetRefreshBehaviour", "Off"
        .Run "SAPExecuteCommand", "PauseVariableSubmit", "On"
	
'### START PROBLEM IS HERE ###	
	.Run "SAPSetFilter", "DS_5", "0CALDAY", calendar_date_rng(), "INPUT_STRING" 'Update Orders from last 2 months
'### END PROBLEM IS HERE ###	
		
	'unfreeze Analysis for variables & filters
        .Run "SAPExecuteCommand", "PauseVariableSubmit", "Off"
        .Run "SAPSetRefreshBehaviour", "On"
    End With
End Sub

Private Function calendar_date_rng() As String
Dim two_months As String, yesterday As String
    two_months = Date - 61
    yesterday = Date - 1
    calendar_date_rng = two_months & " - " & yesterday
End Function

Accepted Solutions (0)

Answers (1)

Answers (1)

sebastian_keim
Explorer
0 Kudos

A W,

Have you tried w/o

.Run"SAPExecuteCommand", "PauseVariableSubmit", "On" and

.Run"SAPExecuteCommand", "PauseVariableSubmit", "Off"?

I ran into a similar issue once and removing the two lines of code worked for me..since I didn't set variables only filters it kinda made sense.

Regards

Seb