ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Refer to Elements in an array (https://www.excelbanter.com/excel-programming/322306-refer-elements-array.html)

Derick[_2_]

Refer to Elements in an array
 
I have a dynamic array whcih would be redimed to hold
values in 20 rows and four columns TestArray(1 to 20, 4)

How can I refer to the array so that the contents of a row
in the array be sent to the worksheet.
For example Range("A1:D1") = TestArray(1,4)

Derick

Tom Ogilvy

Refer to Elements in an array
 
Sub AAYY()
Dim varr As Variant
varr = Worksheets("Sheet1").Range("M5:P25").Value
Worksheets("Sheet2").Range("A1:D1").Value = Application.Index(varr, 1, 0)
End Sub

--
Regards,
Tom Ogilvy

"Derick" wrote in message
...
I have a dynamic array whcih would be redimed to hold
values in 20 rows and four columns TestArray(1 to 20, 4)

How can I refer to the array so that the contents of a row
in the array be sent to the worksheet.
For example Range("A1:D1") = TestArray(1,4)

Derick




Derick Hughes

Refer to Elements in an array
 
Thanks Tom,
I am now trying to work further with the elements of the array.
I am trying to count the number of instances a value occurs in the array
with this statement. However it produces a run time error '424' Object
required.
countNum is declared as a variant.
CountNum =
Application.WorksheetFunction.CountIf(Application. WorksheetFunction.Inde
x(varr, 1, 0), 1)


Regards
Dk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

Refer to Elements in an array
 
Countif/Sumif doesn't work with arrays, only ranges.
--
Regards,
Tom Ogilvy

"Derick Hughes" wrote in message
...
Thanks Tom,
I am now trying to work further with the elements of the array.
I am trying to count the number of instances a value occurs in the array
with this statement. However it produces a run time error '424' Object
required.
countNum is declared as a variant.
CountNum =
Application.WorksheetFunction.CountIf(Application. WorksheetFunction.Inde
x(varr, 1, 0), 1)


Regards
Dk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com