Can anyone please help me with macro parameters?

I want to give parameter to a macro
below is the macro that i am using :

Sub Range()

’ Range Macro


ActiveSheet.ChartObjects(“Chart 2”).Activate
ActiveChart.PlotArea.Select
ActiveWindow.SmallScroll Down:=27
ActiveChart.SetSourceData Source:=Range( _
“Incidents!$A$1:$E$1,Incidents!$A$35:$E$42”)
ActiveWindow.SmallScroll Down:=-27
End Sub

I want to Give parameters to Range Function Range( _
“Incidents!$A$1:$E$1,Incidents!$A$35:$E$42”) $35 Replaced by parameter1 $42 Replaced by Parameter2

thanks & Regards,
Mohd Zaid.

Hi @MohdZaid

Can you try the below code

Sub RangeWithParameters(Parameter1 As Integer, Parameter2 As Integer)
    ’ Range Macro with Parameters
    ’ Use Parameter1 and Parameter2 in your code

    ’ Activating the chart and setting the source data
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SmallScroll Down:=27

    Dim sourceRange As String
    sourceRange = "Incidents!$A$1:$E$1,Incidents!$A$" & Parameter1 & ":$E$" & Parameter2
    ActiveChart.SetSourceData Source:=Range(sourceRange)

    ActiveWindow.SmallScroll Down:=-27
End Sub

Hi ,

i have tried it and it giving error below :

image

please Check ?

Solution for the above is :

Sub Macro1(P1 As Integer, P2 As Integer)

’ Macro1 Macro


ActiveSheet.ChartObjects(“Chart 2”).Activate
ActiveChart.PlotArea.Select
ActiveWindow.SmallScroll Down:=27
Dim sourceRange As String
sourceRange = “Incidents!$A$1:$E$1,Incidents!$A$” & P1 & “:$E$” & P2
ActiveWindow.SmallScroll Down:=24
ActiveChart.SetSourceData Source:=Range( _
(sourceRange))
ActiveWindow.SmallScroll Down:=-27
ActiveWorkbook.Save
End Sub

Thanks for the help.