Excel用vba写一个小程序农户家庭收入采集并形成数据库
Sub AddIncomeData()
Dim ws As Worksheet
Dim lastRow As Long
Dim incomeDate As Date
Dim incomeType As String
Dim incomeAmount As Double
Set ws = ThisWorkbook.Sheets("收入数据")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
incomeDate = InputBox("请输入收入日期(格式为年/月/日):")
incomeType = InputBox("请输入收入类型:")
incomeAmount = InputBox("请输入收入金额:")
ws.Cells(lastRow, 1) = incomeDate
ws.Cells(lastRow, 2) = incomeType
ws.Cells(lastRow, 3) = incomeAmount
MsgBox "收入数据已添加。"
End Sub
Sub CreateIncomeDatabase()
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Sheets("收入数据")
If Err.Number <> 0 Then
Set ws = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
ws.Name = "收入数据"
End If
On Error GoTo 0
With ws
.Cells.ClearContents
.Range("A1:C1").Value = Array("日期", "类型", "金额")
.Range("A1:C1").Font.Bold = True
.Range("A1:C1").HorizontalAlignment = xlCenter
.Range("A1:C1").ColumnWidth = 15
End With
MsgBox "收入数据库已创建。"
End Sub
原文地址: https://www.cveoy.top/t/topic/bzaO 著作权归作者所有。请勿转载和采集!