🦒 VBA応用。
作成日: 2021/08/19
0

excel_20200129_01.jpg

Option Explicit
Private Sub CommandButton1_Click()
Dim last_year, n
last_year = InputBox("去年の体重を入力してください")
n = Cells(Rows.Count, "B").End(xlUp).Row + 1
Range("B" & n).Select
ActiveCell.FormulaR1C1 = last_year
Range("B3:D8").Borders.LineStyle = True
End Sub
Private Sub CommandButton2_Click()
Dim this_year, n
this_year = InputBox("今年の体重を入力してください")
n = Cells(Rows.Count, "C").End(xlUp).Row + 1
Range("C" & n).Select
ActiveCell.FormulaR1C1 = this_year
Range("B3:D8").Borders.LineStyle = True
End Sub
Private Sub CommandButton3_Click()
Dim n, kenko
n = Cells(Rows.Count, "D").End(xlUp).Row + 1
Range("D" & n).Select
If Abs(Range("B" & n) - Range("C" & n)) <= 5 Then
kenko = "健康"
Else
kenko = "不健康"
End If
ActiveCell.FormulaR1C1 = kenko
Range("B3:D8").Borders.LineStyle = True
End Sub
Private Sub CommandButton4_Click()
Range("B3:D8").Clear
Range("B3:D8").Borders.LineStyle = True
End Sub

がソース。
Range(“B3:D8″).Borders.LineStyle = True
で毎回、B3からD8の場所に罫線を引いている。
これは毎回やっている。必要無いのかもしれんが。

後は、特段、難しい事はやってないが、
n = Cells(Rows.Count, “B”).End(xlUp).Row + 1
Range(“B” & n).Select
ActiveCell.FormulaR1C1 = last_year
の所、未だ、あまり理解していない。
課題である。
xlUpって何?
FormulaR1C1って何?
って感じである。


VBSを中心に、ExcelのVBAをやったり、Pythonをやったりしてます。