I am new to VBA Excel. I am trying to compare cells from two different sheets and if they are same, I need to perform the calculation as shown below.
The problem is, when I run I get a Run-Time error '9': Subscript out of range
on the following line Set rng1 = Sheets(“Monday”).Range("K" & i)
Sub updateWOhrs()
Dim i As Integer
Dim j As Integer
Dim rng1 As Range, rng2 As Range
For i = 6 To 15
For j = 1 To 400
Set rng1 = Sheets(“Monday”).Range("K" & i)
Set rng2 = Sheets(“LINKED”).Range("C" & j)
If rng1.Value = rng2.Value Then
Sheets(“LINKED”).Cells(j, 4) = Sheets(“LINKED”).Cells(j, 4) + Sheets(“Monday”).Cells(i, 19)
End If
Next j
Next i
End Sub
尝试将“星期一”替换为“星期一”,将“链接”替换为“链接”(请注意,引号的类型应不同于“”)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.