Vba 回到第一排
我在Excel中的当前列是: A列:代理名称Vba 回到第一排,vba,excel,Vba,Excel,我在Excel中的当前列是: A列:代理名称 B栏:可用性 C列:指针 代码基本上会检查B列是否可用,C列是否有指针。如果两者都为真,那么它将检查下一行代理是否可用。如果不可用,则移动到下一行。如果可用,则将指针移动到该行的C列 当代码到达最后一行时,如何返回到数据的第一行,这是我目前遇到的问题。基本上,整个过程就像一个循环,但我不知道如何以这种方式编码。下面是我的工作代码 Sub Pointer() Dim lgLastRow As Long 'specify the last dat
B栏:可用性
C列:指针 代码基本上会检查B列是否可用,C列是否有指针。如果两者都为真,那么它将检查下一行代理是否可用。如果不可用,则移动到下一行。如果可用,则将指针移动到该行的C列 当代码到达最后一行时,如何返回到数据的第一行,这是我目前遇到的问题。基本上,整个过程就像一个循环,但我不知道如何以这种方式编码。下面是我的工作代码
Sub Pointer()
Dim lgLastRow As Long 'specify the last data row
lgLastRow = Range("A1048576").End(xlUp).Row
Dim lgLastPnt As Long
Dim lgCurrentRow As Long 'specify the currently examined row
Dim nxtRow As Long
Dim nxtAvl As Long
Dim agAly As String
Dim status As String
Dim pnt As String
For lgCurrentRow = 2 To lgLastRow
agAly = Cells(lgCurrentRow, "A")
status = Cells(lgCurrentRow, "B")
pnt = Cells(lgCurrentRow, "C")
If status = "Available" And pnt = "*" Then
Debug.Print agAly
Cells(lgCurrentRow, "C").Select
Selection.Cut
nxtRow = lgCurrentRow + 1
For nxtAvl = nxtRow To lgLastRow
If Cells(nxtAvl, "B") = "Available" Then
Cells(nxtAvl, "C").Select
ActiveSheet.Paste
nxtAvl = nxtAvl + 1
End If
Next
End If
Next
End Sub
回到第一排?添加
范围(“A1”)。选择(假设第1行是第一行)。对不起,我没有注意到@PatricK comment。感谢您的评论。但是,我希望代码将指针放在下一个状态可用的代理中。例如,如果最后一行的详细信息是B列可用,C列带有指针,我希望代码返回到第一行(比如“A1”),看看B列是否可用,这样我就可以将指针放在该行的C列中。
Sub Pointer()
Dim lgLastRow As Long 'specify the last data row
lgLastRow = Range("A1048576").End(xlUp).Row
Dim lgLastPnt As Long
Dim lgCurrentRow As Long 'specify the currently examined row
Dim nxtRow As Long
Dim nxtAvl As Long
Dim agAly As String
Dim status As String
Dim pnt As String
For lgCurrentRow = 2 To lgLastRow
agAly = Cells(lgCurrentRow, "A")
status = Cells(lgCurrentRow, "B")
pnt = Cells(lgCurrentRow, "C")
If status = "Available" And pnt = "*" Then
Debug.Print agAly
Cells(lgCurrentRow, "C").Select
Selection.Cut
nxtRow = lgCurrentRow + 1
For nxtAvl = nxtRow To lgLastRow
If Cells(nxtAvl, "B") = "Available" Then
Cells(nxtAvl, "C").Select
ActiveSheet.Paste
nxtAvl = nxtAvl + 1
End If
Next
End If
Next
Range("A1").Select
End Sub