|
こんにちは
これで如何かな?
データは2行目からで良いですか?
Sub Test()
Dim Ma As Variant, Da As Variant
Dim Co(1) As Long, i As Long, Ad As String
i = 0
With ActiveSheet
For Each Da In Array("1月", "合計")
Ma = Application.Match(Da, .Rows(1), 0)
If IsError(Ma) Then
MsgBox "データなし", vbCritical
Exit Sub
End If
Co(i) = Val(Ma)
i = i + 1
Next Da
Ad = .Range(.Cells(2, Co(0)), .Cells(2, Co(1) - 1)).Address(0, 0)
With .Range(.Cells(2, Co(0)), .Cells(65536, Co(0)).End(xlUp)).Offset(, Co(1) - Co(0))
.Formula = "=SUM(" & Ad & ")"
.Value = .Value
End With
End With
End Sub
|
|