Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Loading dates from spreadsheet into array

I am loading dates into a dynamic array and am getting error message, "run
time error 9, subscript out of range" the dates on the spreadsheet are
formatted as date and look like 2/5/2005 in the formula bar, I tried using
DateValue and DateSerial Function, no help. Stepping through the code it
has 2/5/2005 in the activecell.value. Below is my code, any ideas would
be appreciated.

Public Type Material
MatNum As Integer
MatDate() As Date
End Type

Public MatType(10) As Material

Sub Load_Extraction_Dates_Into_Array()

Dim MatLoopCount, DateCount As Integer
MatLoopCount = 1

Sheets("Extraction Dates").Select
Range("A2").Select

For MatLoopCount = 1 To 10 'loop right through the ten columns of
materials
DateCount = 1 'set/reset date count to beginning
MatType(MatLoopCount).MatNum = DateCount - 1 'start with date
count at 0
Do Until ActiveCell.Value = ""
'on the below code I am getting a run time error 9,
subscript out of range error message
MatType(MatLoopCount).MatDate(DateCount) =
ActiveCell.Value
ActiveCell.Offset([1], [0]).Select 'advance down to next
date
DateCount = DateCount + 1
Loop
'go back to row 2
ActiveCell.Offset([0], [1]).Select 'advance right to next column
of material

Next ' end of looping through the ten columns of materials

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Loading dates from spreadsheet into array

These code changes seem to resolve the problems.

Public Type Material
MatNum As Integer
MatDate(10) As Date
End Type
Public MatType(10) As Material
Sub Test()

Dim MatLoopCount, DateCount As Integer
MatLoopCount = 1

Sheets("Extraction Dates").Select
Range("A2").Select

For MatLoopCount = 1 To 10 'loop right through the ten columns of
materials
DateCount = 1 'set/reset date count to beginning
MatType(MatLoopCount).MatNum = DateCount - 1 'start with date

Do Until ActiveCell.Value = ""
'on the below code I am getting a run time error 9,
MatType(MatLoopCount).MatDate(DateCount) = ActiveCell
ActiveCell.Offset(1, 0).Select 'advance down to next

DateCount = DateCount + 1
Loop
'go back to row 2
ActiveCell.Offset(0, 1).Select 'advance right to next column of
material

Next ' end of looping through the ten columns of materials

End Sub
HTH
Cal

"Arnold Klapheck" wrote:

I am loading dates into a dynamic array and am getting error message, "run
time error 9, subscript out of range" the dates on the spreadsheet are
formatted as date and look like 2/5/2005 in the formula bar, I tried using
DateValue and DateSerial Function, no help. Stepping through the code it
has 2/5/2005 in the activecell.value. Below is my code, any ideas would
be appreciated.

Public Type Material
MatNum As Integer
MatDate() As Date
End Type

Public MatType(10) As Material

Sub Load_Extraction_Dates_Into_Array()

Dim MatLoopCount, DateCount As Integer
MatLoopCount = 1

Sheets("Extraction Dates").Select
Range("A2").Select

For MatLoopCount = 1 To 10 'loop right through the ten columns of
materials
DateCount = 1 'set/reset date count to beginning
MatType(MatLoopCount).MatNum = DateCount - 1 'start with date
count at 0
Do Until ActiveCell.Value = ""
'on the below code I am getting a run time error 9,
subscript out of range error message
MatType(MatLoopCount).MatDate(DateCount) =
ActiveCell.Value
ActiveCell.Offset([1], [0]).Select 'advance down to next
date
DateCount = DateCount + 1
Loop
'go back to row 2
ActiveCell.Offset([0], [1]).Select 'advance right to next column
of material

Next ' end of looping through the ten columns of materials

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Loading dates from spreadsheet into array

Yes it does work, but can I make MatDate a dynamic array? most of the time
there will be 0 elements but at times it can go up to 30.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Loading dates from spreadsheet into array

How about this? I never actually saw the MatDate() Array exceed the 10
elements, since you seem to reset the row(DateCount) and shift one higher in
the MatType() element. It's now dynamic though, so shouldn't make a
difference.

Public Type Material
MatNum As Integer
MatDate() As Date
End Type
Public MatType(10) As Material
Sub test()
Dim MatLoopCount, DateCount As Integer
MatLoopCount = 1

Sheets("Extraction Dates").Select
Range("A2").Select



For MatLoopCount = 1 To 10 'loop right through the ten columns of
materials
DateCount = 1 'set/reset date count to beginning
MatType(MatLoopCount).MatNum = DateCount - 1 'start with date

Do Until ActiveCell.Value = ""

ReDim MatType(MatLoopCount).MatDate(DateCount + 10)

'on the below code I am getting a run time error 9,
MatType(MatLoopCount).MatDate(DateCount) = ActiveCell
ActiveCell.Offset(1, 0).Select 'advance down to next

'MsgBox MatType(MatLoopCount).MatDate(DateCount)
DateCount = DateCount + 1

Loop
'go back to row 2
Cells(2, ActiveCell.Column + 1).Activate


Next ' end of looping through the ten columns of materials

End Sub

"Arnold Klapheck" wrote:

Yes it does work, but can I make MatDate a dynamic array? most of the time
there will be 0 elements but at times it can go up to 30.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loading dates from spreadsheet into array

Might want to change

ReDim MatType(MatLoopCount).MatDate(DateCount + 10)

to

ReDim Preserve MatType(MatLoopCount).MatDate(1 To DateCount)

so you retain the values you have already stored in the array.

--
Regards,
Tom Ogilvy



"CBrine" wrote in message
...
How about this? I never actually saw the MatDate() Array exceed the 10
elements, since you seem to reset the row(DateCount) and shift one higher
in
the MatType() element. It's now dynamic though, so shouldn't make a
difference.

Public Type Material
MatNum As Integer
MatDate() As Date
End Type
Public MatType(10) As Material
Sub test()
Dim MatLoopCount, DateCount As Integer
MatLoopCount = 1

Sheets("Extraction Dates").Select
Range("A2").Select



For MatLoopCount = 1 To 10 'loop right through the ten columns of
materials
DateCount = 1 'set/reset date count to beginning
MatType(MatLoopCount).MatNum = DateCount - 1 'start with date

Do Until ActiveCell.Value = ""

ReDim MatType(MatLoopCount).MatDate(DateCount + 10)

'on the below code I am getting a run time error 9,
MatType(MatLoopCount).MatDate(DateCount) = ActiveCell
ActiveCell.Offset(1, 0).Select 'advance down to next

'MsgBox MatType(MatLoopCount).MatDate(DateCount)
DateCount = DateCount + 1

Loop
'go back to row 2
Cells(2, ActiveCell.Column + 1).Activate


Next ' end of looping through the ten columns of materials

End Sub

"Arnold Klapheck" wrote:

Yes it does work, but can I make MatDate a dynamic array? most of the
time
there will be 0 elements but at times it can go up to 30.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading array into list box r wilcox Excel Programming 5 June 20th 05 11:14 PM
Count rows in text file by loading into array L Mehl Excel Programming 5 September 11th 04 07:15 AM
Loading Excel Array from VB Array Faster ExcelMonkey[_3_] Excel Programming 3 January 22nd 04 02:49 AM
Loading Excel Arrange into VBA array [email protected] Excel Programming 5 December 9th 03 01:48 AM
Loading 3 Dimensional Array Alan Beban[_3_] Excel Programming 0 August 31st 03 03:00 AM


All times are GMT +1. The time now is 09:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"