I’m a novice in VBA and I need your help here.
I’m trying to make a chart with dynamic range based on the FIND of specific text in a column from a range (data series by months, I need a chart of the data for the current and previous 2 months). The idea is the macro to find the column with the current month ad the use it and the previous two columns for chart data. However, I cant get the data for the prior two months – the chart does not creates properly.
This is my code:
```
< Sub Chart()
'
' Chart Macro
'
Dim ra As Range
Dim SC As Range
Dim EC As Range
Set ra = Cells.Find(What:="March-2024", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
Set SC = ra.Offset(0, -3)
Set EC = ra.Offset(1, 0)
If ra Is Nothing Then
MsgBox ("Not found")
Else
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Charts!$B$1:$B$2,SC:EC")
End If
End Sub >
The problem is obviously that the part with SC:EC which are not accepted as ranges.
It should find the start cell and data range for the chart to be set 3 columns back and 1 row below it, but it doesn't works...
Can you tell me where is my mistake?
Thank you in advance
Мирослав Христов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.