Private Sub last_column()
Dim Cell As Range
With ThisWorkbook.Sheets("Sheet1")
lcol = .Cells(1, Columns.Count).End(xlToLeft).Column
MsgBox ("Last column is " & lcol)
For i = 4 To 7
'below line is raising an error
Cell(i, lcol).Value = Application.Countif(Range(.Cells("i", 3), .Cells("i", "lcol")), "<= 7")
Next i
End With
End Sub
Редактировать:
Я изменил код следующим образом, но, несмотря на то, что ошибки теперь нет, ячеек тоже нет.
Private Sub last_column()
Dim Cell As Range
Dim i As Double
With ThisWorkbook.Sheets("Sheet1")
lcol = .Cells(1, Columns.Count).End(xlToLeft).Column
MsgBox ("Last column is " & lcol)
For i = 4 To 7
.Cells(i, lcol).Value = Application.Countif(.Range(.Cells(i, 3), .Cells(i, lcol)), "<= 7")
Next i
End With
End Sub