Paulo_3456
New Member
- Joined
- Jul 25, 2018
- Messages
- 15
Hello everyone,
I tried everything before coming here with my code. It gives me the following error :
Run-time error '1004'. Application-defined or operation-defined error.
The goal of the macro is to set dynamic table range (located in "d_ws" worksheet) for chart's (located in "e_ws" worksheet) data source.
In order to get this dynamic table range, I define two variables (first and last table rows) using MATCH + COUNTIF functions.
Indeed, in the "d_ws" worksheet, datas are disposed with a Lookup value in first column (M).
Then, when I want to set the range with the variables, I get the 1004 error. Here is my code :
The name "tick_tab" is referring to a named cell in e_ws worksheet.
If you need more info to understand where the error could come from, please let me know !
Thanks a lot for helping if you can !
I tried everything before coming here with my code. It gives me the following error :
Run-time error '1004'. Application-defined or operation-defined error.
The goal of the macro is to set dynamic table range (located in "d_ws" worksheet) for chart's (located in "e_ws" worksheet) data source.
In order to get this dynamic table range, I define two variables (first and last table rows) using MATCH + COUNTIF functions.
Indeed, in the "d_ws" worksheet, datas are disposed with a Lookup value in first column (M).
Then, when I want to set the range with the variables, I get the 1004 error. Here is my code :
Code:
Public Sub graph_update()
Dim first_row As Double
Dim last_raw As Double
Dim Stock_ticker As String
Dim dates_range As Range
Dim cht As ChartObject
Dim e_ws As Worksheet
Dim d_ws As Worksheet
Application.ScreenUpdating = False
'Chart and worksheets Definition
Set e_ws = ActiveWorkbook.Worksheets("Equities")
Set d_ws = ActiveWorkbook.Worksheets("Datas_fs")
Set cht = e_ws.ChartObjects("GraphSharePrice")
'Lookup Value
Stock_ticker = WorksheetFunction.VLookup(e_ws.Range("tick_tab"), e_ws.Range("C:D"), 2, False)
'First and last row definition
first_row = Application.WorksheetFunction.Match(Stock_ticker, d_ws.Range("M:M"), 0)
last_row = (Application.WorksheetFunction.Match(Stock_ticker, d_ws.Range("M:M"), 0) _
+ Application.WorksheetFunction.CountIf(d_ws.Range("M:M"), Stock_ticker) - 1)
'THIS LINE IS GETTING ME THE 1004 ERROR
Set dates_range = d_ws.Range(d_ws.Cells(first_row - 1, 14), d_ws.Cells(first_row - 1 - 7, 14))
Set prices_range = d_ws.Range(d_ws.Cells(first_row - 1, 18), d_ws.Cells(first_row - 1 - 7, 18))
cht.Activate
ActiveChart.SetSourceData Source:=Range(dates_range, prices_range)
Application.ScreenUpdating = True
End Sub
The name "tick_tab" is referring to a named cell in e_ws worksheet.
If you need more info to understand where the error could come from, please let me know !
Thanks a lot for helping if you can !