【发布时间】:2017-10-24 05:58:58
【问题描述】:
我真的需要帮助来查明我的 excel vba 出了什么问题。这里完全是初学者。
基本上,vba 代码将对工作表进行“过滤”。奇怪的是,当过滤其他类别时,vba 有效。但是在 1 个类别上,它只是一直给我 运行时错误 1004(对象_worksheet 的方法范围失败)。
调试模式将始终精确定位到代码行:
Range(Mid(rangeToHide, 1, 199)).Select
代码如下:
Private Sub cboPopulateDept_Change()
Dim sh As Worksheet
Dim rw As Range
Dim RowCount As Integer
Dim rangeToHide As String
Dim emptyRow As Integer
unHide
If cboPopulateDept.Value = "ALL" Or cboPopulateDept.Value = "" Then
Exit Sub
End If
RowCount = 1
Set sh = ActiveSheet
For Each rw In sh.Rows
If RowCount >= 6 Then
If sh.Cells(RowCount, 1).Value Like "TOP Innovation Projects - Vision 2020 - Participating?" Then
Exit For
End If
If sh.Cells(RowCount, 3).Value <> cboPopulateDept.Value And sh.Cells(RowCount, 3).Value <> "" Then
'sh.Cells(RowCount, 3).EntireRow.Hidden = True
'sh.Cells(RowCount + 1, 3).EntireRow.Hidden = True
rangeToHide = rangeToHide & RowCount & ":" & RowCount + 1 & ","
RowCount = RowCount + 2
Else
RowCount = RowCount + 1
End If
Else
RowCount = RowCount + 1
End If
Next rw
rangeToHide = Mid(rangeToHide, 1, Len(rangeToHide) - 1)
If Len(rangeToHide) <= 201 Then
Range(rangeToHide).Select
Selection.EntireRow.Hidden = True
Else
Range(Mid(rangeToHide, 1, 199)).Select
Selection.EntireRow.Hidden = True
Range(Mid(rangeToHide, 201, Len(rangeToHide))).Select
Selection.EntireRow.Hidden = True
End If
'Range(rangeToHide).Select
'Selection.EntireRow.Hidden = True
Range("A8:A9").Select
End Sub
谢谢
干杯, 湿度
【问题讨论】: