PC Review


Reply
Thread Tools Rate Thread

Array values with UBound

 
 
mareharbor@yahoo.com
Guest
Posts: n/a
 
      12th Jun 2007
I am having trouble putting my array values into another sheet. I know
that the correct values are in there but i can't get them to output. I
have two variations. One uses UBound and the other just uses my
counter from building the array.

Public Sub DIFFREC2()
Windows("factor.xls").Activate
Dim MRange As Range
Set MRange = Range(Range("F1"), Range("F1").End(xlDown))
Dim cell As Variant
Dim rw As Integer
Dim x As Integer
Dim y As Integer
Dim arrTicker() As String
rw = 0
For Each cell In MRange
If cell.Value = "PAYD" Then
ReDim Preserve arrTicker(4, rw)
arrTicker(0, rw) = cell.Offset(0, -5).Value
arrTicker(1, rw) = cell.Offset(0, -4).Value
arrTicker(2, rw) = cell.Offset(0, -3).Value
arrTicker(3, rw) = cell.Offset(0, -2).Value
rw = rw + 1
End If
Next cell
Windows("TEST.xls").Activate
Sheets("CBOIPRIN").Select
x = 0
For y = 0 To rw - 1
' or y = 0 To UBound(arrTicker) either doesn't work

Cells(x, 1).Value = arrTicker(0, y)
Cells(x, 2).Value = arrTicker(1, y)
Cells(x, 3).Value = arrTicker(2, y)
Cells(x, 4).Value = arrTicker(3, y)
x = x + 1
Next

End Sub

 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      12th Jun 2007
Cells(x, 1) will error when x = 0 since Cells() is 1-based.

If I understand what you're doing, you could perhaps use:

Public Sub DIFFREC2()
Dim rDest As Range
Dim rCell As Range

Set rDest = Workbooks("TEST.xls").Sheets("CBOIPRIN").Cells(1, 1)
With Workbooks("factor.xls").Sheets(1)
For Each rCell In .Range(.Range("F1"), _
.Range("F1").End(xlDown))
With rCell
If .Text = "PAYD" Then
rDest.Resize(1, 4).Value = _
.Offset(0, -5).Resize(1, 4).Value
Set rDest = rDest.Offset(1, 0)
End If
End With
Next rCell
End With
End Sub

In article <(E-Mail Removed)>,
(E-Mail Removed) wrote:

> I am having trouble putting my array values into another sheet. I know
> that the correct values are in there but i can't get them to output. I
> have two variations. One uses UBound and the other just uses my
> counter from building the array.
>
> Public Sub DIFFREC2()
> Windows("factor.xls").Activate
> Dim MRange As Range
> Set MRange = Range(Range("F1"), Range("F1").End(xlDown))
> Dim cell As Variant
> Dim rw As Integer
> Dim x As Integer
> Dim y As Integer
> Dim arrTicker() As String
> rw = 0
> For Each cell In MRange
> If cell.Value = "PAYD" Then
> ReDim Preserve arrTicker(4, rw)
> arrTicker(0, rw) = cell.Offset(0, -5).Value
> arrTicker(1, rw) = cell.Offset(0, -4).Value
> arrTicker(2, rw) = cell.Offset(0, -3).Value
> arrTicker(3, rw) = cell.Offset(0, -2).Value
> rw = rw + 1
> End If
> Next cell
> Windows("TEST.xls").Activate
> Sheets("CBOIPRIN").Select
> x = 0
> For y = 0 To rw - 1
> ' or y = 0 To UBound(arrTicker) either doesn't work
>
> Cells(x, 1).Value = arrTicker(0, y)
> Cells(x, 2).Value = arrTicker(1, y)
> Cells(x, 3).Value = arrTicker(2, y)
> Cells(x, 4).Value = arrTicker(3, y)
> x = x + 1
> Next
>
> End Sub

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
UBound array problem xavi garriga Microsoft Excel Programming 2 24th May 2009 11:19 AM
Error on UBound with Dynamic Array =?Utf-8?B?SmF5?= Microsoft Access VBA Modules 9 6th Nov 2006 06:17 PM
Array Ubound gti_jobert Microsoft Excel Programming 6 27th Mar 2006 10:34 PM
UBound of multi-dimensional array? paulharvey Microsoft Excel Programming 2 16th Aug 2005 06:34 PM
dif Ubound for member array when debugging Eric Microsoft Excel Programming 1 28th May 2005 09:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 PM.