|
-
Jul 7th, 2006, 01:46 PM
#1
Thread Starter
New Member
subscript out of range (Excel)
long story short, i haven't used dynamic variables before and i'm not sure why i keep getting this subscript out of range error -- as soon as it gets to the row i've starred it crashes wih the error - in the debugger i can see that the value of ActiveCell is just "Trade Ticket"
VB Code:
Dim trigger As String
Dim Labels() As String
Dim Data() As Variant
Dim inputRow As Integer
Dim inputCol As Integer
Dim counter As Integer
counter = 0
inputRow = 1
inputCol = 1
Do While trigger <> "InputEnd" ' finds rows with data
If trigger = "Input" Then ' takes data out of relevant rows
inputRow = ActiveCell.Row
inputCol = ActiveCell.Column
Do While ActiveCell.Offset(0, 1) <> "End"
Label = ActiveCell.Value
**** Labels(counter) = ActiveCell.Value
Data(counter) = ActiveCell.Offset(1, 0).Value
counter = counter + 1
Loop
Else
End If
inputRow = inputRow + 1
Cells(inputRow, inputCol).Select
trigger = ActiveCell.Value
Loop
Last edited by RobDog888; Jul 7th, 2006 at 01:52 PM.
Reason: Added [vbcode] tags
-
Jul 7th, 2006, 01:52 PM
#2
Re: subscript out of range (Excel)
Welcome to the Forums.
I dont see where your dimensioning the array Data or Labels with the number of elements needed.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 7th, 2006, 01:53 PM
#3
Re: subscript out of range (Excel)
you need to Set then increase the amount of "space" that each variable has
Normally an array has as many spaces as its set to..
DIm tmp(3) as string
tmp has 4 spaces for data 0,1,2,3
now a dynamic array is not "setup"
DIm tmp() as string
theres no spaces.. you need to Redim to start it then increase it
Redim tmp(0)
then
Redim Preserve tmp(1) <-using preserve keeps any data in the array
VB Code:
Dim trigger As String
Dim Labels() As String
Dim Data() As Variant
Dim inputRow As Integer
Dim inputCol As Integer
Dim counter As Integer
counter = 0
inputRow = 1
inputCol = 1
Do While trigger <> "InputEnd"
If trigger = "Input" Then
inputRow = ActiveCell.Row
inputCol = ActiveCell.Column
Do While ActiveCell.Offset(0, 1) <> "End"
Label = ActiveCell.Value
[B]If counter = 0 Then
ReDim Labels(0)
ReDim Data(0)
Else
ReDim Preserve Labels(counter)
ReDim Preserve Data(counter)
End If[/B]
Labels(counter) = ActiveCell.Value
Data(counter) = ActiveCell.Offset(1, 0).Value
counter = counter + 1
Loop
Else
End If
inputRow = inputRow + 1
Cells(inputRow, inputCol).Select
trigger = ActiveCell.Value
Loop
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 7th, 2006, 02:06 PM
#4
Thread Starter
New Member
Re: subscript out of range (Excel)
ok - i get it, i must have gotten confused when i was reading through examples, i thought Labels() would just set up a dynamic array -- for this problem it's fine to just set it up as Labels(100) and eveything seems to be working perfectly, i'll play around with the new info you gave me and see if i can get it to work both ways
thanks for the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|