ThijsVBANoob
New Member
- Joined
- Jan 10, 2024
- Messages
- 1
I'm really new at this and need help.
after searching the web I created 2 VBA's to plot a graph from data ranges however
1 VBA is going correctly as the datarange is in consecutive order and easy added
however the 2nd test VBA that I want to test (and eventually implement in my main project) is not working.
Setup is columns A to AB but my datarange source for the graph needs to be column B-D-E etc. till last data column
Using Union function and determine last data and last row it's not plotting a graph but also not coming up want a runtime error.
'Data needs to be entered as followed:
'Data from row 2 till lastRow of with data entry
'Data from Column x till lastcolumn
'Column data need to be Column skipped = B (skipping C) D (skipping E) till lastcolumn
The code that I've so far is
Dim ws As Worksheet
Dim rng As Range
Dim cht As Object
Dim LastRow As Long
Dim LastColumn As Long
Dim currentcol As Long
Set ws = ThisWorkbook.Sheets("DataFilter")
Set cht = Sheets("Chart").Shapes.AddChart2
cht.Chart.ChartType = xlLine
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
LastColumn = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column
Set rng = ws.Range(ws.Cells(2, 1), ws.Cells(LastRow, 1))
For currentcol = 3 To lastcol Step 2
Set rng = Union(rng, ws.Cells(1, currentcol).Resize(LastRow))
Next currentcol
cht.Chart.SetSourceData Source:=rng
Hope somebody can help me
after searching the web I created 2 VBA's to plot a graph from data ranges however
1 VBA is going correctly as the datarange is in consecutive order and easy added
however the 2nd test VBA that I want to test (and eventually implement in my main project) is not working.
Setup is columns A to AB but my datarange source for the graph needs to be column B-D-E etc. till last data column
Using Union function and determine last data and last row it's not plotting a graph but also not coming up want a runtime error.
'Data needs to be entered as followed:
'Data from row 2 till lastRow of with data entry
'Data from Column x till lastcolumn
'Column data need to be Column skipped = B (skipping C) D (skipping E) till lastcolumn
The code that I've so far is
Dim ws As Worksheet
Dim rng As Range
Dim cht As Object
Dim LastRow As Long
Dim LastColumn As Long
Dim currentcol As Long
Set ws = ThisWorkbook.Sheets("DataFilter")
Set cht = Sheets("Chart").Shapes.AddChart2
cht.Chart.ChartType = xlLine
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
LastColumn = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column
Set rng = ws.Range(ws.Cells(2, 1), ws.Cells(LastRow, 1))
For currentcol = 3 To lastcol Step 2
Set rng = Union(rng, ws.Cells(1, currentcol).Resize(LastRow))
Next currentcol
cht.Chart.SetSourceData Source:=rng
Hope somebody can help me