excel 中使用vba实现列的筛选
表格第一行内有M,N两个字母,如何使用VBA实现筛选?按钮一只显示第一行内含有M的列,按钮二只显示第一行内含有N的列,按钮三显示全部...
表格第一行内有M,N两个字母,如何使用VBA实现筛选?
按钮一只显示第一行内含有M的列,按钮二只显示第一行内含有N的列,按钮三显示全部 展开
按钮一只显示第一行内含有M的列,按钮二只显示第一行内含有N的列,按钮三显示全部 展开
4个回答
展开全部
下面是3个宏的代码,分别绑定到3个按钮上
Sub combutton1()
Dim a As Range
Range("A1:iv1").EntireColumn.Hidden = False
For Each a In Range("A1:iv1")
If a = "M" Or a = "m" Then a.EntireColumn.Hidden = True
Next
End Sub
Sub combutton2()
Dim a As Range
Range("A1:iv1").EntireColumn.Hidden = False
For Each a In Range("A1:iv1")
If a = "N" Or a = "n" Then a.EntireColumn.Hidden = True
Next
End Sub
Sub combtton3()
Dim a As Range
endcol = Range("iv1").End(xlToLeft).Column
Range("A1:iv1").EntireColumn.Hidden = False
End Sub
Sub combutton1()
Dim a As Range
Range("A1:iv1").EntireColumn.Hidden = False
For Each a In Range("A1:iv1")
If a = "M" Or a = "m" Then a.EntireColumn.Hidden = True
Next
End Sub
Sub combutton2()
Dim a As Range
Range("A1:iv1").EntireColumn.Hidden = False
For Each a In Range("A1:iv1")
If a = "N" Or a = "n" Then a.EntireColumn.Hidden = True
Next
End Sub
Sub combtton3()
Dim a As Range
endcol = Range("iv1").End(xlToLeft).Column
Range("A1:iv1").EntireColumn.Hidden = False
End Sub
追问
谢谢!还有点小问题
endcol = Range("iv1").End(xlToLeft).Column
这句是干什么的啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
录制三个宏就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Sub xianshiM()
Dim EndC As Integer, i As Integer
Columns.Hidden = False
EndC = Range("A1").End(xlToRight).Column
For i = 1 To EndC
If InStr(Cells(1, i), "M") > 0 Then
Columns(i).Hidden = False
Else
Columns(i).Hidden = True
End If
Next
End Sub
Sub xianshiN()
Dim EndC As Integer, i As Integer
Columns.Hidden = False
EndC = Range("A1").End(xlToRight).Column
For i = 1 To EndC
If InStr(Cells(1, i), "N") > 0 Then
Columns(i).Hidden = False
Else
Columns(i).Hidden = True
End If
Next
End Sub
Sub xianshquanbu()
Columns.Hidden = False
End Sub
Dim EndC As Integer, i As Integer
Columns.Hidden = False
EndC = Range("A1").End(xlToRight).Column
For i = 1 To EndC
If InStr(Cells(1, i), "M") > 0 Then
Columns(i).Hidden = False
Else
Columns(i).Hidden = True
End If
Next
End Sub
Sub xianshiN()
Dim EndC As Integer, i As Integer
Columns.Hidden = False
EndC = Range("A1").End(xlToRight).Column
For i = 1 To EndC
If InStr(Cells(1, i), "N") > 0 Then
Columns(i).Hidden = False
Else
Columns(i).Hidden = True
End If
Next
End Sub
Sub xianshquanbu()
Columns.Hidden = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询