アメリカの大学生活---日記

ミネソタ州立大学ムーアヘッド校 会計学部を5月に卒業して帰国し、税務の仕事してます。

練習問題15(Withの練習) メモ

 

excel-ubara.com

 

With ステートメント

excel-ubara.com

 

Sub 練習問題15()
  Dim i As Long
  Dim ixR As Long
  Dim ixC As Long
  Dim ws1 As Worksheet
  Dim ws2 As Worksheet
  Set ws1 = Worksheets("練習15")
  Set ws2 = Worksheets("練習15_回答")
  ws2.Range("A1").CurrentRegion.Offset(1, 1).ClearContents
  With ws1
    For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
      ixC = 2
      Do Until ws2.Cells(1, ixC) = .Cells(i, 1)
        ixC = ixC + 1
      Loop
      ixR = 2
      Do Until ws2.Cells(ixR, 1) = .Cells(i, 2)
        ixR = ixR + 1
      Loop
      ws2.Cells(ixR, ixC) = ws2.Cells(ixR, ixC) + .Cells(i, 3)
    Next
  End With
End Sub