Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Transfer range to array etc.

I am trying to use the following code to:

Transfer a 2 column range into "vertical arrays" two arrays
Find each element of the 1st array in a worksheet range
Print the corresponding element in the second array into a cell offset from
the range

My code is not working. I am getting an error that I can't track down.

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x, 1)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i)
End With
End If
Next i

End Sub

Thanks is advance


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Transfer range to array etc.

This works - but not sure if you get the results you expect?

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer, x As Variant, y As Variant
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i, 1)
End With
End If
Next i

End Sub

--
Cheers
Nigel



"AD108" wrote in message
...
I am trying to use the following code to:

Transfer a 2 column range into "vertical arrays" two arrays
Find each element of the 1st array in a worksheet range
Print the corresponding element in the second array into a cell offset
from
the range

My code is not working. I am getting an error that I can't track down.

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x, 1)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i)
End With
End If
Next i

End Sub

Thanks is advance




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Transfer range to array etc.

The variables x and y are not shown dimmed, but assuming variants.
You should be getting a subscript out of range error on the line :
..Cells(intPos, 11) = y(i)
because the array is 2D. You have the correct syntax for x, so the same for
y

However, you do not need 2 arrays ; you can dump the 2 columns in 1 array
x = Range("BS9:BT300")
and
.Cells(intPos, 11) = x(i,2)

NickHK

"AD108" wrote in message
...
I am trying to use the following code to:

Transfer a 2 column range into "vertical arrays" two arrays
Find each element of the 1st array in a worksheet range
Print the corresponding element in the second array into a cell offset

from
the range

My code is not working. I am getting an error that I can't track down.

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x, 1)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i)
End With
End If
Next i

End Sub

Thanks is advance




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default Transfer range to array etc.

AD108 wrote:

My code is not working. I am getting an error that I can't track down.

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x, 1)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i)
End With
End If
Next i

End Sub


Several errors:

#1 -- Your IsError() statement doesn't do anything -- If intPos does
have an error, your Application.Match statement will terminate the
routine.
#2 -- As is, the only way the Match routine can have an error is if
every cell in the 2nd column is empty. You have to add the 3rd
parameter to tell it you want an exact match.
#3 -- You're referring to y() as a 1-dimensional array. It's
2-dimensional

If I understood your description correctly, I think what you want is:

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer
x = Range("BS9:BS15")
y = Range("BT9:BT15")
For i = 1 To UBound(x, 1)
If Not
IsError(Application.Match(x(i,1),ActiveSheet.Colum ns(2),0)) Then
intPos = Application.Match(x(i, 1),ActiveSheet.Columns(2),0)
ActiveSheet.Cells(intPos, 11) = y(i, 1)
End If
Next i
End Sub

I'm not sure why you couldn't "track down" the errors. They were
either flagged by VBA during line by line execution or by watching the
value of "intPos" in the watch window.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Transfer range to array etc.

Thanks,

That worked
"Nigel" wrote in message
...
This works - but not sure if you get the results you expect?

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer, x As Variant, y As Variant
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i, 1)
End With
End If
Next i

End Sub

--
Cheers
Nigel



"AD108" wrote in message
...
I am trying to use the following code to:

Transfer a 2 column range into "vertical arrays" two arrays
Find each element of the 1st array in a worksheet range
Print the corresponding element in the second array into a cell offset
from
the range

My code is not working. I am getting an error that I can't track down.

Sub Honolulu()
Dim intPos As Integer
Dim i As Integer
x = Range("BS9:BS300")
y = Range("BT9:BT300")
i = 1
For i = 1 To UBound(x, 1)
intPos = Application.Match(x(i, 1), ActiveSheet.Columns(2))
If Not IsError(intPos) Then
With ActiveSheet
.Cells(intPos, 11) = y(i)
End With
End If
Next i

End Sub

Thanks is advance






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
How to transfer specific range to another range ? ghost Excel Discussion (Misc queries) 0 June 11th 08 05:10 PM
Named Range Transfer Graham Haughs Excel Discussion (Misc queries) 9 February 21st 07 02:58 PM
VBA Array Transfer JAY Excel Programming 4 June 4th 04 09:01 AM
transfer cell range gav meredith Excel Programming 5 April 21st 04 02:08 AM
Transfer Range to Array Steven Drenker Excel Programming 1 November 9th 03 06:41 PM


All times are GMT +1. The time now is 05:48 PM.

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

About Us

"It's about Microsoft Excel"