VBA行属性variables

我试图取消隐藏一系列的行。 这是在一个循环内完成的,所以我使用了variables; 这是代码:

For i = 2 To lastrow If Workbooks("Discrepancies1").Worksheets(1).Cells(i, 8) = "USRFLG02=T" Then a = Workbooks("Discrepancies1").Worksheets(1).Cells(i, 46).Value b = Application.WorksheetFunction.CountIf(c, a) Workbooks("Discrepancies1").Worksheets(1).Rows("i: i + b - 1").Hidden = False End If Next End If 

但是,运行这会给我最后一行代码上的types不匹配错误。 我已经检查了所有的variables,他们应该是。 看起来VBA不喜欢冒号(表示范围)和variables一起使用。 我可以运行这个没有variables,或没有范围,但我不能有两个。 build议?

 With Workbooks("Discrepancies1").Worksheets(1) For i = 2 To lastrow If .Cells(i, 8) = "USRFLG02=T" Then a = .Cells(i, 46).Value b = Application.CountIf(c, a) .Rows(i & ":" & i + b - 1).Hidden = False End If Next End With