我尝试对活动工作簿中每个工作表中的每个表进行排序,并重置所有过滤器。
请注意,每个表都是一个数据透视表。
Sub ResetFilters()
Dim ws As Worksheet
Dim wb As Workbook
Dim listObj As ListObjects
For Each ws In ActiveWorkbook.Worksheets
For Each listObj In ws
With ActiveSheet.listObj.Sort.SortFields.Clear
End With
Next listObj
Next ws
End Sub
收到错误:"对象不支持此属性或方法"在第7行。
答案 0 :(得分:3)
假设您的意思是清除过滤器并删除排序,您可以使用:
Sub ResetFilters()
Dim ws As Worksheet
Dim wb As Workbook
Dim listObj As ListObject
For Each ws In ActiveWorkbook.Worksheets
For Each listObj In ws.ListObjects
If listObj.ShowHeaders Then
listObj.AutoFilter.ShowAllData
listObj.Sort.SortFields.Clear
End If
Next listObj
Next ws
End Sub
答案 1 :(得分:0)
这适用于对前一个答案的一个小改动。只需使用ShowAutoFilter属性而不是ShowHeaders。 ShowAutoFilter是引用这些内容的属性:explained here
(我会对其他答案发表评论,但我需要50“声望”-_-)
答案 2 :(得分:0)
7行解决方案 这将显示所有数据而无需删除过滤器,并且在未过滤的工作表上也不会失败。
BoW_vect = CountVectorizer(min_df=10, max_features=500)
vect_train = BoW_vect.fit_transform(X_train)
vect_cv = BoW_vect.transform(X_cv)
vect_test = BoW_vect.transform(X_test)
# #arrays for storing range of K and storing accuracy scores.
k_range= np.arange(1,16,1)
auc_cv=np.zeros(15)
auc_train = np.zeros(15)
# #Simple Cross Validation
count = 0
for i in range (1,30,2):
kd_BOW = KNeighborsClassifier(n_neighbors=i, algorithm = 'kd_tree')
kd_BOW.fit(vect_train.toarray(),Y_train.toarray())
kd_pred = kd_BOW.predict(vect_cv.toarray())
pred_train_BOW = knn.predict(vect_train.toarray())
auc_cv[count] = roc_auc_score(Y_cv,kd_pred)*float(100)
auc_train[count] = roc_auc_score(Y_train,pred_train_BOW)*float(100)
print('\nCV AUC for k=', i)
print('is', auc_cv[count])
count = count +1
发布者的VBA可能在遇到未过滤的图纸时失败。
要完全删除每个过滤器,只需将第4 + 5行替换为Sub RemoveFilters()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
ws.ShowAllData
Next ws
End Sub
。