Dealing with ranges of any size

mhorsnell

New Member
Joined
Nov 2, 2017
Messages
2
Hi Everyone,

I am writing a sub that asks the user to enter a 2D range, which is then sorted, averaged and interpolated/extrapolated to find a y value belonging to an x value entered by the user. The sub needs to be capable of dealing with ranges of any length. I am fairly new to VBA so I do not understand how to do this. I know this is not right but it is what I started with just to write something that worked for the averaging, sorting and interpolation.

The range entered is defined as a range, it is split into two columns, xr and yr. The only way I could make it work was to have xr and yr defined as Single. Below is my Dim section

Dim rowc, i, j, k, yrcount As Integer
Dim xr(1 To 10), yr(1 To 10), xrsort(1 To 10), yrsort(1 To 10), yrsortav(1 To 10) As Single
Dim x As Single ' x is the number not present in the range entered by the user
Dim x1, x2, tempx, tempy As Single
Dim y1, y2, y As Single '
Dim rangein As Range ' this is the range that must be entered by the user after the button is pressed
Dim Ret As String
Dim yrsum, yrav As Single

What do I need to Dim xr and yr as to make them work for ranges of all sizes?

Thanks in advance
Michael
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
mhorsnell,

I would suggest that your change the following line of code:

Dim rowc, i, j, k, yrcount As Integer

To this:

Dim rowc As Long, i As Long, j As Long, k As Long, yrcount As Long


And, do the same type of declaration statements for the rest of your variables in a single row statement.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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
Back
Top