excel vba使用工作表函数

时间:2015-05-29 17:15:41

标签: excel vba excel-vba

您好我刚才有一个关于在多个工作表中实现worksheetfuncion的快速问题。我不太明白为什么我的代码在这一行中产生应用程序定义或对象定义的错误

count = Application.WorksheetFunction.CountBlank(ws.Range(Cells(2, 6), Cells(14, 6)))

我的代码的一部分显示在下面

Dim ws As Worksheet
Dim i As Integer, j As Integer, k As Integer, x As Integer, y As Integer, z As Integer
Dim lastrow As Integer, lastcoln As Integer
Dim rowht As Double
Dim count As Integer, total As Integer

lastrow = Sheet2.UsedRange.Row - 1 + Sheet2.UsedRange.Rows.count
lastcoln = Sheet2.UsedRange.Column - 1 + Sheet2.UsedRange.Columns.count

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Legend" And ws.Name <> "Master Schedule" Then
lastrow = ws.UsedRange.Rows.count
ws.Range("A" & lastrow + 1) = "Total Crew Count: " & lastrow - 1
For j = 6 To lastcoln

count = Application.WorksheetFunction.CountBlank(ws.Range(Cells(2, 6), Cells(14, 6)))

Next j
End If
Next ws

感谢您的帮助。非常感谢!

1 个答案:

答案 0 :(得分:0)

count = Application.WorksheetFunction.CountBlank(ws.Range(Cells(2, 6), Cells(14, 6)))更改为count = Application.WorksheetFunction.CountBlank(ws.Range(ws.Cells(2, 6), ws.Cells(14, 6)))