|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 838225419 于 2023-7-7 10:39 编辑
拜托各位大师看一下这个代码如何修改
Sub 按钮2_Click()
[a3:ae3].Clear
If [c4] <> "" Then [aa3] = ">=" & [c4] '日期起
If [c5] <> "" Then [ab3] = "<=" & [c5] '日期止
If [p4] <> "" Then [ad3] = ">=" & [p4] '日期起
If [p5] <> "" Then [ae3] = "<=" & [p5] '日期止
If [e4] <> "" Then [f3] = [e4]
If [e5] <> "" Then [c3] = [e5]
If [g4] <> "" Then [d3] = [g4]
If [g5] <> "" Then [e3] = [g5]
x = Sheet1.Range("b65536").End(xlUp).Row '最后行数
Sheet1.Range("b4:u" & x).AdvancedFilter 2, [aa2:ab3], [b7:u7] '高级筛选最简代码
Sheet1.Range("b4:u" & x).AdvancedFilter 2, [ad2:ae3], [b7:u7] '高级筛选最简代码
End Sub
如果:
If [c4] <> "" Then [aa3] = ">=" & [c4] '日期起
If [c5] <> "" Then [ab3] = "<=" & [c5] '日期止
则执行:
Sheet1.Range("b4:u" & x).AdvancedFilter 2, [aa2:ab3], [b7:u7] '高级筛选最简代码
否则执行:
If [p4] <> "" Then [ad3] = ">=" & [p4] '日期起
If [p5] <> "" Then [ae3] = "<=" & [p5] '日期止
Sheet1.Range("b4:u" & x).AdvancedFilter 2, [ad2:ae3], [b7:u7] '高级筛选最简代码
这一句如何改:if Sheet1.Range("b4:u" & x).AdvancedFilter 2, [aa2:ab3], [b7:u7] Then Sheet1.Range("b4:u" & x).AdvancedFilter 2, [ad2:ae3] [b7:u7] 不会出错,拜托
|
|