I've got a function as follows:
It does everything I need it to do (in this case, make certain lines in a graph visible or not depending on the input value). However, the function ends with the focus on the chart, not in the last used cell. I tried fixing this by saving the ActiveCell in the beginning and then Activating it again at the end of the function, however this has no effect.
I've used this solution (saving the ActiveCell) in other VBA subroutines (also altering the contents of a graph) and it works like a charm, so I don't entirely understand why it doesn't work here.
Is there a relevant difference due to this being a Function as opposed to a Sub(routine)?
Code:
Function VerificarInfinito(a As Double)
Set c = ActiveCell
ActiveSheet.ChartObjects("Planta").Activate
If (a >= 3) Then
ActiveChart.SeriesCollection(2).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(13).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(14).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(1).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(4).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(16).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(3).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(15).Format.Line.Transparency = 1
ElseIf a < 1 / 3 Then
ActiveChart.SeriesCollection(2).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(13).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(14).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(1).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(4).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(16).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(3).Format.Line.Transparency = 0
ActiveChart.SeriesCollection(15).Format.Line.Transparency = 0
Else
ActiveChart.SeriesCollection(2).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(13).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(14).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(1).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(4).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(16).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(3).Format.Line.Transparency = 1
ActiveChart.SeriesCollection(15).Format.Line.Transparency = 1
End If
c.Activate
VerificarInfinito = a
End Function
It does everything I need it to do (in this case, make certain lines in a graph visible or not depending on the input value). However, the function ends with the focus on the chart, not in the last used cell. I tried fixing this by saving the ActiveCell in the beginning and then Activating it again at the end of the function, however this has no effect.
I've used this solution (saving the ActiveCell) in other VBA subroutines (also altering the contents of a graph) and it works like a charm, so I don't entirely understand why it doesn't work here.
Code:
Sub Drop_Esq()
a = Range("S4").Value
Set c = ActiveCell
'... do stuff with the graph
c.Activate
End Sub
Is there a relevant difference due to this being a Function as opposed to a Sub(routine)?