I am trying to pass 3 values to the 2nd sub, the name of the "channel" every 3 columns are a different data set with a different name. "Test" which is the names of the test file to extract the channels from that data and create graphs from it.
Sub PickTests()
Dim Channame() As String
Dim Amplitude() As String
Dim Integration() As String
Dim LvlCross() As String
Dim MaxAnal() As String
Dim Chans As Double
Dim x As Long
Dim TestList() As Double
Dim i As Long
Worksheets("Channel_List.csv").Activate
For i = 1 To (Cells(i + 2, 1).Value = 0)
Channame(i) = Cells(i + 1, 1)
Amplitude(i) = Cells(i + 1, 2)
Integration(i) = Cells(i + 1, 3)
LvlCross(i) = Cells(i + 1, 4)
MaxAnal(i) = Cells(i + 1, 5)
Chans = i + 1
Next i
Worksheets("HomeSheet").Activate
' Set numrows = number of rows of data.
NumRows = Range("A14", Range("A14").End(xlDown)).Rows.Count
' Select cell a1.
Range("A4").Select
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
TestList(x) = Cells(x, 1).Value
ActiveCell.Offset(1, 0).Select
Next x
For i = 1 To Chans
If Amplitude(i) = y Then
AmplitudeDistribution(Channame(i), TestList)
End If
Next i
End Sub
Sub AmplitudeDistribution(Channame As String, Test() As Long)
Dim i, j, y, x As Long
Dim wsname As String
wsname = (Channame & "_Amp_Dist")
x = UBound(Test, 1) - LBound(Test, 1) + 1
Worksheets.Add.Name = wsname
Charts.Add
ActiveChart.ChartType = xlLineStacked
ActiveChart.Location Where:=wsname, Name:=Channame
For i = 1 To x
ActiveChart.SeriesCollection.NewSeries
Sheets(Test(i) & "_out_Amp_Dist.csv").Activate
With ActiveSheet
Set FindColumn = .Range("1:1").Find(What:=Channame, LookIn:=xlValues)
End With
y = FindColumn.Row
For j = 1 To (Cells(y, j + 1).Value = 0)
NumRow(i) = j
Next j
ActiveChart.SeriesCollection(i).Values = ActiveSheet.Range(Cells(y, 1), Cells(y + 1, j))
ActiveChart.SeriesCollection(i).Name = Channame
Next i
End Sub
I get an error type mismatch error trying to pass TestList to the 2nd sub. How can I get arround this?
Edit: Thank you everyone for your help, I come from a c++ background so didn't realise how dumb dynamic arrays are in VBA! All works perfectly now! (Well not all, but it passes everything to the 2nd sub, no i am just wrestling with charts....)
Variant, and use a plural parameter name, i.e.ByRef tests As VariantDim i, j, y, x As Longis declaringxas aLong, and everything else as an implicitVariant.For i = 1 To (Cells(i + 2, 1).Value = 0)doesn't iterate once given any value ofi, even if the VBA assignment operator returned the assigned value (it doesn't) and was different than the comparison operator (it isn't). We all write bugs and bad code, in any language. And I don't do C++ but if it lets you downcast an array ofDoubleinto an array ofLonglike that, it's C++ that's dumb.