Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

data arrays

ResolvedVersion 2016

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

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Freeze Rows and Columns to keep lables displayed

You can freeze rows and columns in your worksheet so they don't move.

This allows you to keep row and column labels displayed on your screen as you move through a large worksheet.

Click below and/or to the right of the cell(s) you want to freeze. (NB. Excel freezes ALL the rows above and ALL the columns to left of the selected cell)

Click on the 'Windows' menu and selct 'Freeze Panes'.

Lines appear in your worksheet. The required rows and columns are frozen and remain on your screen as you move through your worksheet.

To unfreeze rows and columns, click on 'Window' menu and select 'Unfreeze Panes'.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.