excel - VBA嵌套循环计算多个员工小时
问题描述
我一直在努力获得一个时间表宏,它将进行数据转储并做一些事情。最终我不熟悉 VBA 的语法并且已经接近但是我需要帮助来完成这个。下面将是我正在处理代码的代码和注释以及电子表格参考的屏幕截图。
我的问题是如何使用 vars 正确编写语法?例如在这行代码中: If IsNumeric(Cells("Fr").Value) Then 我收到错误并且不确定如何从循环中输入 r 值。这适用于我遇到错误但不知道如何使用 r 来识别行的其他几行。
Sub sum()
Dim r As Integer, c As Integer, s As Double, t As Integer, g As Integer
r = 2 'looping var
c = 3 'looping var
s = 0 'var for sum
g = 0
t = ActiveSheet.UsedRange.Rows.Count 'var for total rows
Do Until r = t
If Not IsEmpty(Range("Ar").Value) = True Then 'check if user name is present then
'Detect the next cell that contains data in the user name column
'Use that number between the two as a var (g) that will be used to run the embedded looping
'essentially redefining the other loop each time to account for the different number of clock ins per user
Do Until c = g 'Loop for until the next name was detected via var (g)
If IsNumeric(Cells("Fr").Value) Then 'check if Billable has a number then
s = s + Range("r, F").Value 'adds cell value (numbers only) to sum
c = c + 1 'add 1 to the value of c
Loop 'closes embedded loop once values have been added up
Range("Fr") = s 'Replace Cell (Fr) with the sum value
s = 0 'reset the value of the sum
r = r + 1
Loop
End Sub
解决方案
推荐阅读
- c# - 错误 CS5001:程序“main.exe”不包含适合入口点的静态“Main”方法
- python - 线程写入顺序
- javascript - 选择具有相同 ID 的多个 div
- java - 我们如何更改 atlasmap-2.1.6 的上下文路径?
- google-analytics - 如何在新的 GA4 帐户中使用 Multi-Channel Funnels Reporting API
- swift - 更改文件时,Swift Playground 散文消失了
- python - 如何使用 Pytorch 中的截断反向传播(闪电)在很长的序列上运行 LSTM?
- c# - 如何从gridview获取单元格值
- postgresql - Kafka JDBCSinkConnector Schema 异常:带有 schemas.enable 的 JsonConverter 需要“schema”和“payload”
- firebase - 20% 的 Facebook 凭据在 Firebase 身份验证中丢失电子邮件