Excel VBA导航按钮条件滚动
发布时间:2022-03-01 22:50:17 484
相关标签:
我目前有一份有两张工作表的工作表。
第一页是“数据库”样式的平面文件,其中包含与不同记录相关的单行信息。另一个工作表从数据库工作表中获取信息,并将其放入可滚动视图中。
除了导航箭头,我的一切都很完美。代码当前在每个记录中滚动(当前记录一直滚动到末尾)。我在左上角有相关的验证列表,它首先按位置过滤员工列表,然后按向主管报告过滤,然后是该主管下的受限员工列表。
我希望导航箭头从第一个“向领导报告”记录开始,一直过滤到“向领导报告”的结尾(而不是从1到全部)。
我想不出来,救命啊!:)
工作表示例
Sub ViewLogUp()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim rngA As Range
Dim lRec As Long
Dim lRecRow As Long
Dim lLastRec As Long
Dim lastRow As Long
Application.EnableEvents = False
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("PartsData")
Dim wsSR As Worksheet
Set wsSR = wksSelRec
Set rngA = ActiveCell
With historyWks
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row - 1
lLastRec = lastRow - 1
End With
With inputWks
lRec = .Range("CurrRec").Value
If lRec > 1 Then
.Range("CurrRec").Value = lRec - 1
lRec = .Range("CurrRec").Value
lRecRow = lRec + 1
.Range("InputA").Value = wsSR.Range("SelValA").Value
.Range("InputB").Value = wsSR.Range("SelValB").Value
rngA.Select
End If
End With
Application.EnableEvents = True
End Sub
Sub ViewLogDown()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim rngA As Range
Dim lRec As Long
Dim lRecRow As Long
Dim lLastRec As Long
Dim lastRow As Long
Application.EnableEvents = False
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("PartsData")
Dim wsSR As Worksheet
Set wsSR = wksSelRec
Set rngA = ActiveCell
With historyWks
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row - 1
lLastRec = lastRow - 1
End With
With inputWks
lRec = .Range("CurrRec").Value
If lRec < lLastRec Then
.Range("CurrRec").Value = lRec + 1
lRec = .Range("CurrRec").Value
lRecRow = lRec + 1
.Range("InputA").Value = wsSR.Range("SelValA").Value
.Range("InputB").Value = wsSR.Range("SelValB").Value
rngA.Select
End If
End With
Application.EnableEvents = True
End Sub
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报