繁体   English   中英

vba代码是什么,可以把员工每天的伙食登记在“清单”里?

[英]What is the vba code to register employees' daily meals in a "list"?

晚安,

我在 excel 制作了一个屏幕,供食堂员工登记 go 每天午餐的员工。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM