2017-12-06 11 views
-1

以下をExcelで達成しようとしていて、VBAを使用する必要があると考えています。どんな助けでも大歓迎です!Excel VBA - xからyの範囲の入力セルに基づいた出力セルの数式(リスト)

エクセル入力

Cell A1 = A2*B2*C2 
A2 ranges from x to y 
B2 ranges from x to y 
C2 ranges from x to y 

Excel出力

Original Inputs, Formula Calculation (vertical list) 

A2 B2 C2 , A1 
+0

は、xからyに及ぶ、あなたが意味ですか列または行として?マクロレコーダーでExcelのコードを試してみましたか? – Xabier

+0

返事ありがとうございます。私は列として信じています。 A2、B2、C2の範囲が1から3の場合、出力は次のようになります。 行1 - 1 1 1、1 ......行2 - 1 1 2、2 ....行3 - 1 1 3、3、およびect それぞれが独自の列になります –

答えて

0

私は、次のコードは、あなたを助けになると思う:A2ことで

Sub foo2() 
Dim A2(), B2(), C2() As Variant 'Declare the variables as Variant arrays 
Dim LastRowA, LastRowB, LastRowC As Long 

LastRowA = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row 'find the last row with data on column A 
LastRowB = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row 'find the last row with data on column B 
LastRowC = Sheet1.Cells(Rows.Count, "C").End(xlUp).Row 'find the last row with data on column C 

A2 = Sheet1.Range("A1:A" & LastRowA) 'take all values form A1 to the last row in that column into the A2 array 
B2 = Sheet1.Range("B1:B" & LastRowB) 
C2 = Sheet1.Range("C1:C" & LastRowC) 

For x = LBound(A2) To UBound(A2) 'loop from the begining of the array until the end 
    Sheet1.Cells(x, 6).Value = A2(x, 1) 'enter the values of A2 into the column F which is the number 6 
    Sheet1.Cells(x, 7).Value = B2(x, 1) 'edit this values to "paste" the values wherever you wish 
    Sheet1.Cells(x, 8).Value = C2(x, 1) 
    Sheet1.Cells(x, 9).FormulaR1C1 = "=RC[-3]*RC[-2]*RC[-1]" 'this will enter the formula in those cells 
Next x 
End Sub 
関連する問題