Function with disjoined cells as input

eviMogwai

New Member
Joined
Jul 4, 2011
Messages
26
Hello folks.
I am trying to program a classification function in excel 2007 on win XP. the classification works such that I have to compare input to preset curves and find the lowest curve that the input does not cross.
This manifests in taking 9 cells as input and looping them through some checking algorithms to produce an output.

Unfortunately i run into problems with my input. I have tried several versions, one of which is:
Code:
function Rating( ParamArray rLevels() As Variant)
which returns a "#NAME?" when called.

As I am new to VBA and have only the first clue as to error management, I tried remake this into a sub
Code:
Sub Rating()
Dim rLevels() as Variant
rLevels = Range("C13, C16, C19, C22, C25, C28, C31, C34, C37").Select
where the cells are the ones to be supplied as argument for the function.

When stepped through this throws an "Run-time Error '13' incompatible types" without a marker.

My questions:
1) Is this a valid way to debug? Are these equivalent code snippets?
2) What part of the code throws the error '13'? Is it perhaps further into the code?
3) How is a better way to use 9 non-joined cells as a range/double argument in a function?

Grateful for your help
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
It should be like this

Code:
Sub Rating()
Dim rLevels() As Range
Set rLevels = Range("C13, C16, C19, C22, C25, C28, C31, C34, C37")
 
Upvote 0
In fact it should be without the ()

Code:
Sub Rating()
Dim rLevels As Range
Set rLevels = Range("C13, C16, C19, C22, C25, C28, C31, C34, C37")
 
Upvote 0
This code seems to give me an array
Code:
 rLevels() = Array("C13", null, null, "C16", null, null , "C19" '... )
I would like an array giving me each of the cells (values at the least) in consecutive order, as
Code:
rLevels() = Array("C13", "C16", "C19", '...
'or the values in each corresponding cell
 
Upvote 0
This code seems to give me an array
Code:
 rLevels() = Array("C13", null, null, "C16", null, null , "C19" '... )
I would like an array giving me each of the cells (values at the least) in consecutive order, as
Code:
rLevels() = Array("C13", "C16", "C19", '...
'or the values in each corresponding cell

The code is formatted wrong, I mean that rLevels looks like that (as gained from debug.print() ). Hopefully it's clear enough =)
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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