VBA Dynamic Chart Not Working Properly

SouthernGent0327

New Member
Joined
Jan 30, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
So I have the following sample set:

Days of OperationPackages
1020
1550
18100

The workbook is setup to take in data from a UserForm and formulas transfer this data to a dummy range for graphing. There are multiple ranges like shown above starting at Row 12 to 2015. Here is the current code used to generate the XY scatter Plots:

Sub NormPerm1()
Dim ws As Worksheet
Dim NormPRange As Range
Dim NormPChart As Chart
Dim LastRow As Long
Dim StartCell As Range

Set ws = ActiveSheet
Set StartCell = Range("AG12")

ActiveSheet.UsedRange

Set NormPChart = Charts.Add

LastRow = ws.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

Set NormPRange = ws.Range("AG12:AG" & LastRow & ", AH12:AH" & LastRow)

With NormPChart

.SetSourceData Source:=NormPRange
.HasTitle = True
.ChartTitle.Text = "Normalized Permeate Flow"
.ChartType = xlXYScatter
.PlotBy = xlColumns

End With


End Sub

Currently, the graphing function works, but the X-axis is arbitrarily graphing values on the X-axis. So effectively just counting the entries and not actually using the correct days of operations values. How can I make the x and y axis dynamically update as new data is added to the table? Also, is this the best way of accomplishing my goal or would an alternate method work better for this application? Thanks in advance for your time and help. Also, here is a copy of the output from the full scale table:

Capture.PNG


That x-axis should be values ranging from 13 to 600 days.
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

SouthernGent0327

New Member
Joined
Jan 30, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range

Set sht = ActiveSheet
Set StartCell = Range("AG12")

'Refresh UsedRange
  ActiveSheet.UsedRange

'Find Last Row
  LastRow = sht.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

'Select Range
  sht.Range("AG12:AG" & LastRow).Select
  
  Charts.Add

Here is the correct code, the graph orientation is correct, only the x values displayed are the number of points and not actual data points.
 

SouthernGent0327

New Member
Joined
Jan 30, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Dim ws As Worksheet
Dim NormPRange As Range
Dim NormPChart As Chart
Dim LastRow As Long
Dim StartCell As Range

Set ws = ActiveSheet
Set StartCell = Range("AG12")

ActiveSheet.UsedRange

Set NormPChart = Charts.Add

LastRow = ws.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

Set NormPRange = ws.Range("AG12:AG" & LastRow & ", AH12:AH" & LastRow)

With NormPChart
    .SetSourceData Source:=NormPRange
    .HasTitle = True
    .ChartTitle.Text = "Normalized Permeate Flow"
    .ChartType = xlXYScatter
End With

'With NormPChart.Axes(xlCategory)
'.MinimumScale = ws.Range("AG13")
'.MaximumScale = ws.Range("AG72")
'End With

Can anyone please tell me why this graphs the number of data points instead of actual data values?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,653
Messages
5,626,101
Members
416,161
Latest member
David1966Lewis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top