Dim book1 As Workbook
Set book1 = Workbooks("Book1.xlsx")
html
Sub 数値がゼロの行を削除()
Dim i As Long
Dim LastRow As Long
'最終行を取得
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
'行を逆順にループ
For i = LastRow To 1 Step -1
If Cells(i, 2).Value = 0 Then
'行削除
Rows(i).Delete
End If
Next i
End Sub
Sub SumUntilYesterday()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") ' シート名は適宜変更
Dim lastCol As Long
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column ' 最後の列を取得
Dim total As Double
total = 0
Dim i As Long
Dim targetDate As Date
targetDate = Date - 1 ' 昨日の日付
For i = 2 To lastCol ' B列(2)から最終列まで
If IsDate(ws.Cells(1, i).Value) Then
If ws.Cells(1, i).Value <= targetDate Then
total = total + ws.Cells(2, i).Value
End If
End If
Next i
ws.Cells(2, 1).Value = total ' A2セルに合計値を表示(必要に応じて変更)
End Sub