![]() |
配列を使ってセル範囲に入力する:Excel VBA プログラミング入門 |
スポンサードリンク | |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") End Sub |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Dim lastRow1 As Long Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") With Sh1 lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row If lastRow1 = 1 Then Exit Sub End With End Sub |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Dim lastRow1 As Long Dim myData As Variant Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") With Sh1 lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row If lastRow1 = 1 Then Exit Sub myData = .Range("A2:D" & lastRow1).Value End With End Sub |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Dim lastRow1 As Long, lastRow2 As Long Dim i As Long Dim myData As Variant Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") With Sh1 lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row If lastRow1 = 1 Then Exit Sub myData = .Range("A2:D" & lastRow1).Value ReDim Preserve myData(1 To lastRow1 - 1, 1 To 5) For i = LBound(myData) To UBound(myData) myData(i, 5) = myData(i, 3) * myData(i, 4) Next i End With End Sub |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Dim lastRow1 As Long, lastRow2 As Long Dim i As Long Dim myData As Variant Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") With Sh1 lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row If lastRow1 = 1 Then Exit Sub myData = .Range("A2:D" & lastRow1).Value ReDim Preserve myData(1 To lastRow1 - 1, 1 To 5) For i = LBound(myData) To UBound(myData) myData(i, 5) = myData(i, 3) * myData(i, 4) Next i .Range("A2:D" & lastRow1).ClearContents End With End Sub |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Dim lastRow1 As Long, lastRow2 As Long Dim i As Long Dim myData As Variant Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") With Sh1 lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row If lastRow1 = 1 Then Exit Sub myData = .Range("A2:D" & lastRow1).Value ReDim Preserve myData(1 To lastRow1 - 1, 1 To 5) For i = LBound(myData) To UBound(myData) myData(i, 5) = myData(i, 3) * myData(i, 4) Next i .Range("A2:D" & lastRow1).ClearContents End With With Sh2 lastRow2 = .Range("A" & Rows.Count).End(xlUp).Row + 1 .Range("A" & lastRow2).Resize(UBound(myData), UBound(myData, 2)).Value = myData End With End Sub |
Sub prog3_1() Dim Sh1 As Worksheet, Sh2 As Worksheet Dim lastRow1 As Long, lastRow2 As Long Dim i As Long Dim myData As Variant Set Sh1 = Worksheets("入力") Set Sh2 = Worksheets("データ") With Sh1 lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row If lastRow1 = 1 Then Exit Sub '配列に入力データを読み込む myData = .Range("A2:D" & lastRow1).Value '配列の要素数を変更 ReDim Preserve myData(1 To lastRow1 - 1, 1 To 5) '金額の計算 For i = LBound(myData) To UBound(myData) myData(i, 5) = myData(i, 3) * myData(i, 4) Next i '入力データをクリアする .Range("A2:D" & lastRow1).ClearContents End With With Sh2 'データシートの最下行の次の行位置を求める lastRow2 = .Range("A" & Rows.Count).End(xlUp).Row + 1 'データシートへ配列を書き出す .Range("A" & lastRow2).Resize(UBound(myData), UBound(myData, 2)).Value = myData End With End Sub |
スポンサードリンク
PageViewCounter
Since2006/2/27