在"list"中注册员工日常膳食的 vba 代码是什么?



晚安,

我有一个用excel制作的屏幕,供食堂员工登记每天去吃午饭的员工。

Sub test()
Range("N5:Q5").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("N5:Q5").Select
ActiveCell.FormulaR1C1 = "Request"
Range("N6:Q21").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
Range("N21:Q21").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("N21").Select
ActiveCell.FormulaR1C1 = "TOTAL:"
Range("Q21").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-14]C:R[-1]C)"
Range("Q7:Q21").Select
Range("Q21").Activate
Selection.Style = "Currency"
Range("N7").Select
ActiveCell.FormulaR1C1 = "Daily menu"
Range("Q7").Select
ActiveCell.FormulaR1C1 = "$4 "
Range("N8").Select
ActiveCell.FormulaR1C1 = "Extra drink"
Range("Q8").Select
ActiveCell.FormulaR1C1 = "$1 "
Range("N9").Select
ActiveCell.FormulaR1C1 = "Extra dessert"
Range("Q9").Select
ActiveCell.FormulaR1C1 = "$1.20 "
Range("Q10").Select
ActiveCell.FormulaR1C1 = "Code employee:"
Range("F6").Select
ActiveCell.FormulaR1C1 = "Name employee:"
Range("G5:J5").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("G6:J6").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Columns("F:F").EntireColumn.AutoFit
Range("P4").Select
ActiveCell.FormulaR1C1 = "=NOW()"
Range("P4").Select
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss"
End Sub

此屏幕注册菜单,右侧显示价格摘要,列末显示总额。然而,我想把这一信息记录在另一张"表格"中;列表";员工的代码、姓名、午餐时间、午餐吃了什么以及餐价,但我不知道该使用哪个代码,因为当员工注册时,它应该出现在列表中的下一行。当您在主页上注册时,您将保存在";列表";。

试试这个:您可以通过将CELLNAME更改为要保存的单元格来保存每一列。

Sub SaveLunch()
Dim LunchRow As Long
'Determine New or Existing Invoice
If Sheet1.Range("XX999").Value = Empty Then 'Check if first record
LunchRow = Sheet2.Range("A99999").End(xlUp).Row + 1  'First Available Row
Else: 'Add row
LunchRow = Sheet1.Range("XX999").Value 'Existing Lunch Row
End If
Sheet2.Range("A" & LunchRow).Value = Sheet1.Range("CELLNAME").Value 'Save column 1
Sheet2.Range("C" & LunchRow).Value = Sheet1.Range("CELLNAME").Value 'Save column 2
Sheet2.Range("D" & LunchRow).Value = Sheet1.Range("CELLNAME").Value 'Save column 3
Sheet2.Range("E" & LunchRow).Value = Sheet1.Range("CELLNAME").Value 'Save column 4
Sheet2.Range("F" & LunchRow).Value = Sheet1.Range("CELLNAME").Value 'Save column 5
Sheet2.Range("G" & LunchRow).Value = Sheet1.Range("CELLNAME").Value 'Save column 6

End If
Sheet1.Range("XX999").Value = Sheet1.Range("XX999").Value + 1
End Sub

最新更新