#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Array Help

Below is a sub that I wrote to multiply range "a" and range "b" to get range
"c". Range "a" would be a1:a10, range b would be b1:b10, range "d" would be
"c1:c10". It is not working and am getting an "object required" error. I am
assuming that the error message refers to darray but is darray not an object?
I am writing this code so I could avoid functions in the worksheet where my
rows changes often. I don't want to copy and paste the function but just
have the excel automatically perform the calculation upon an event change.
Also, if you could refer me to a book or website where there is more array
examples or information, it would be appreciated.

Sub test()

Dim myarray As Variant
Dim mycount As Integer

aarray = Worksheets("sheet1").Range("a")
barray = Worksheets("sheet1").Range("b")
darray = Worksheets("sheet1").Range("d")


For mycount = LBound(aarray) To UBound(aarray) '0 to 3
darray(mycount, 1).Value = WorksheetFunction.Product(aarray(mycount,
1), barray(mycount, 1))
Next mycount

End Sub
--
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 207
Default Array Help

Daviv

Alan is pretty much the expert on arrays, so if he says you don't need
arrays, you don't need arrays. If you want a generic code that
populates a third named range with the product of corresponding values
in two similarly sized ranges, you might try:

Sub test()

Dim mycount As Integer
Dim aarray As Range
Dim barray As Range
Dim darray As Range

Set aarray = Worksheets("sheet1").Range("a")
Set barray = Worksheets("sheet1").Range("b")
Set darray = Worksheets("sheet1").Range("d")

For mycount = 1 To aarray.Rows.Count
darray.Cells(mycount, 1) = aarray.Cells(mycount, 1) *
barray.Cells(mycount, 1)
Next mycount

End Sub

Good luck.

Ken
Norfolk, Va


On Jun 4, 4:53 pm, Alan Beban <unavailable wrote:
Arrays aren't necessary; simply array enter into Range("C1:C10") =a*b

If you have to do it in VBA, Range("c1:c10").FormulaArray = "=a*b"

Alan Beban



Daviv wrote:
Below is a sub that I wrote to multiply range "a" and range "b" to get range
"c". Range "a" would be a1:a10, range b would be b1:b10, range "d" would be
"c1:c10". It is not working and am getting an "object required" error. I am
assuming that the error message refers to darray but is darray not an object?
I am writing this code so I could avoid functions in the worksheet where my
rows changes often. I don't want to copy and paste the function but just
have the excel automatically perform the calculation upon an event change.
Also, if you could refer me to a book or website where there is more array
examples or information, it would be appreciated.


Sub test()


Dim myarray As Variant
Dim mycount As Integer


aarray = Worksheets("sheet1").Range("a")
barray = Worksheets("sheet1").Range("b")
darray = Worksheets("sheet1").Range("d")


For mycount = LBound(aarray) To UBound(aarray) '0 to 3
darray(mycount, 1).Value = WorksheetFunction.Product(aarray(mycount,
1), barray(mycount, 1))
Next mycount


End Sub- Hide quoted text -


- Show quoted text -



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
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
variant array containing cel adresses convert to actual ranges-array Peter[_21_] Excel Programming 5 December 10th 03 09:50 PM


All times are GMT +1. The time now is 02:03 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"