roshanK
roshanK

Reputation: 409

excel vba sub script out of bound error

I have tried to get the output of following code but its giving out error

Following is the code:


Dim strRisk() As String
Dim riskLen As Integer

strRisk = SplitMultiDelims(ActiveCell.Offset(0, 9).Value, "@")
MsgBox UBound(strRisk)

Error:


Run time error '9':
Subscript out of range

The value in the refering cell is not null, what else could be the reason? is there another way to do this.

Please help me out

Upvotes: 0

Views: 746

Answers (2)

Jüri Ruut
Jüri Ruut

Reputation: 2530

If you define Dim strRisk() As String as a dynamic array, then you need Redim strRisk (n) and further refer to strRisk with a corresponding index: strRisk(i)=....

If you want to store strRisk as array, use Dim strRisk As Variant, then strRisk=... will work.

Upvotes: 2

whytheq
whytheq

Reputation: 35557

Add a BreakPoint on the line that begins strRisk and then run the code.

If you now run the line Excel.ActiveCell(0, 9).select in the Immediate Window is it definitely the cell you wish this code to target?

Upvotes: 0

Related Questions