Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

VBA Array - return value to a cell

  Asked By: Waldemar    Date: Oct 15    Category: MS Office    Views: 2187
  

I have a name range in excel that contains text values (10 items, but
may be more in the future) and I can't figure out how to write code
that will read down the list (array) and write one value in to a cell
and record a calculation result before writing in the next text value
in the array. Any help would be greatly appreciated. thanks...

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Grant Jones     Answered On: Oct 15

I'm not totally clear on what you are asking, but perhaps these
examples will help. Step through these using F8 while looking at the
View-Locals Window to see what is going on. Be sure to define MyList
and MySum as named ranges in your sheet.


Sub Example1()
A = Range("MyList")
'A becomes a 2 dimensional array
'access elements by A(row, column)
s = 0
NRows = UBound(A, 1)
For r = 1 To NRows
s = s + A(r, 1)
Next
Range("MySum") = s
End Sub

Sub Example2()
s = 0
For Each c In Range("MyList")
s = s + c
Next
Range("MySum") = s
End Sub

 
Didn't find what you were looking for? Find more on VBA Array - return value to a cell Or get search suggestion and latest updates.




Tagged: