Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I assume that you mean B1:B8 for the quantities.
I would be tempted to let Excel do the calculation: Range("C1:C8").FormulaR1C1 = "=RC[-2]*RC[-1]" However, you are probably interested in more complex issues and you could do the following in VBA: Sub test() Dim priceArr As Variant Dim quantityArr As Variant Dim revenueArr As Variant Dim iRows As Integer Dim i As Integer priceArr = Range("A1:A8").Value quantityArr = Range("B1:B8").Value iRows = UBound(priceArr) ReDim revenueArr(1 To iRows, 1 To 1) For i = 1 To iRows revenueArr(i, 1) = priceArr(i, 1) * quantityArr(i, 1) Next i Range("C1").Resize(iRows, 1).Value = revenueArr End Sub Bear in mind that ranges are two dimensional even if only one row or column is involved. We could have hard coded the upper limit of 8 rows but this way is more flexible. We could also calculate the lower limit. -- John Green - Excel MVP Sydney Australia "Henrik" wrote in message ... I Know this is a very simple question, but as I am just learning VBA and your help is greatly appreciated. I have two arrays: priceArr = .Range("A1:A8").Value quantityArr = .Range("B1:B3").Value I would like to make a very simple calculation [price * quantity = revenue ] for each row and output the result in colum C (i.e. C1:C8). How do I go about that? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Very basic VBA question. | Excel Discussion (Misc queries) | |||
basic question | New Users to Excel | |||
Basic question - how to do an average | Excel Worksheet Functions | |||
Basic question...sorry | Excel Worksheet Functions | |||
Basic question | Excel Discussion (Misc queries) |