'Generate chart based on data extracted through looping
I wan't transfer data from selected range for non blank cells from selected worksheets by looping process in a workbook and transfer to a master sheet named statistics to generate scatter plot with trendline equation. However, my code does not seem to transfer any data and I am also getting error while generating a loop.
Sub Button4_Click()
Dim i As Long
Dim wkSht As Worksheet
Dim wsC As Worksheet
Dim rowCount As Integer
Dim nextEmptyRow As Integer
Dim Rng As Range
Dim Cell As Range
Dim CHARTDATA As Range
Dim Ch As Chart
Set wsC = ThisWorkbook.Worksheets("Statistics")
Set Rng = Cells.Range("C5:G5")
wsC.Shapes.AddChart2(240, xlXYScatter).Select
wsC.Shapes("Chart 1").IncrementLeft 179.25
wsC.Shapes("Chart 1").IncrementTop 175.5
ActiveWindow.SmallScroll Down:=12
wsC.Shapes("Chart 1").IncrementTop 45
ActiveChart.PlotArea.Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).XValues = "='Statistics'!$A$1:$A$50"
ActiveChart.FullSeriesCollection(2).Values = "='Statistics'!$B$1:$B$50"
ActiveChart.FullSeriesCollection(2).Name = "=""Depth vs Moisture"""
nextEmptyRow = wsC.Cells(Rows.Count, "A").End(xlUp).Row + 1
For Each wkSht In ThisWorkbook.Worksheets
If wkSht.Name <> "Statistics" Then
For Each Cell In Rng
If Cell.Value <> "" Then
wsC.Range("A" & nextEmptyRow).Value = ActiveCell.Range("C5:G5").Value
wsC.Range("B" & nextEmptyRow).Value = ActiveCell.Offset(4, 0).Range("C5:G5").Value
End If
Next
End If
Next wkSht
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

