Martin has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Excel VBA Advanced course
Data Arrays
Hi Jens,
I hope you are well. I have a challenge for you.
I have created a data array containing all my raw data.
I have then added a line that finds and returns the column number with the heading Head Force Z.
Now that I have this I want to loop through this column in my data array from the lower to the upper bound selecting 5 cells at a time. I want to return the lowest value for each step.
Is there a way to specify a range within an array?
After selecting 5 cells I am going to be increasing it to 10,15...up to 80 cells at a time.
What I have written so far is below..
Sub exceedance()
Sheets("Raw Data").Range("a1").Select
cols = Sheets("Raw Data").Range("a1").CurrentRegion.Columns.Count
For j = 1 To cols
If Sheets("Raw Data").Cells(1, j) = "Head Force (Z-Axis)" Then
HeadForceZ_col = j
Exit For
End If
Next j
dataarr = Sheets("Raw Data").Range("a1").CurrentRegion
For i = (LBound(dataarr, 1) + 1) To UBound(dataarr, 1)
minval = Application.WorksheetFunction.Min(dataarr(i, HeadForceZ_col), dataarr(i + 5, HeadForceZ_col))
'this compares the 5th and 1st cell and returns the minimum of the 2 not the cells between
Next i
End Sub
Kind regards
Martin
RE: Data Arrays
Hi Martin,
Thank you for the forum question.
Yes it is a good challenge.
My first thought was to create another array with 5 rows and then move 5 rows at the time from the first array to test for min. I have a course tomorrow but I have time to test my idea Friday and I will come to you Friday.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
RE: Data Arrays
I will also give this a try tomorrow see how I get on.
Just to clarify I am moving 1 cell at a time down the array analysing 5 rows each time.
RE: Data Arrays
Hi Martin,
If you send me an email, I will send you the solution.
jens.bonde@stl-training.co.uk
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector