******解决****** 我试图做的是有一个公式计算每47行到一个范围,其结束由单元格值确定。
我尝试过使用If语句 - 案例变量和许多其他调整,但我不知所措。
代码是将从第200行开始的索引匹配公式添加到每个人的最后一个计数。每个人的计数在行M中总计,并从行190开始,并且每47行也跳过
如果M的值为0,并且要输入的行数与M的值相同,我试图让循环输入注释
'Sub LOGVOIL()
'FIND VIOLATIONS
Dim lastRow As Long, I As Long
Dim LR As Integer
Dim FR As Integer
Dim addall As Integer, addone As Integer
FR = 10
lastRow = Range("P190").End(xlDown).Row
For I = 190 To lastRow Step 47
LR = Range("M" & I).Value
addone = I + FR ' adds 10 rows to the start postion of the loop starts at row 200
addall = I + LR ' adds the end row count to the end of the loop
If (LR = 0) Then ' if the value of M is 0 then we enter a comment on the first row of the loop
Set dlv = Range("a" & addone)
With dlv
.Value = "No Violations"
End With
Else ' any other value we add a formula to the end of the count
Set dlv = Range("A" & addone & ":A" & addall) ' range here be a200:a202 if the count of m was 2
With dlv
.Formula = _
"=IFERROR(INDEX(RDBMergeSheet!E:E,MATCH(""log""&K197&"" ""&M197,RDBMergeSheet!$N:$N,0)),"""")"
.forumla = .Value
End With
End If
'*********************************************
' tryed using cases
'select Case LR
'Case 0
'Set dlv = Range("a" & addone)
'With dlv
' .Value = "No Violations"
'End With
'Case Else
'Set dlv = Range("A" & addone & ":A" & addall)
' With dlv
' .Formula = _
' "=IFERROR(INDEX(RDBMergeSheet!E:E,MATCH(""log""&K197&"" ""&M197,RDBMergeSheet!$N:$N,0)),"""")"
' .forumla = .Value
'End With
'End Select
Next I
结束Sub`
案例选择工作但这里仅为0是如何运行
我认为我在代码中有一个简单的错误,但是我不知道任何帮助或方向都会非常感激。
我能够弄清楚 这是工作代码
Sub logvil()
Dim lastRow As Long, I As Long
Dim LR As Integer, cr As Integer, FR As Integer
Dim addall As Integer, addone As Integer
' starts at row 200
lastRow = Range("P190").End(xlDown).Row
For I = 190 To lastRow Step 47
FR = 10
LR = Range("M" & I).Value
cr = LR + FR
addone = I + FR
addall = I + cr
Select Case LR
Case 0
Set dlv = Range("a" & addone)
With dlv
.Value = "No Violations"
End With
Case Else
Set lv = Range("A" & addone & ":A" & addall)
With lv
.Formula = _
"=IFERROR(INDEX(RDBMergeSheet!E:E,MATCH(""log""&K197&"" ""&M197,RDBMergeSheet!$N:$N,0)),"""")"
.Formula = .Value
End With
End Select
Next I
End Sub