2010-11-02 88 views
1

列A在某些行中具有值,在其他行中为空白。VBA将光标向下移动到列A中具有值的下一行?

我在一些其他列。在我所在的行中,A列是空白的。

我想要一个宏,它将移动我的光标 - 保留在当前列 - 直到它在列A的行不是空白。

这似乎很容易,但我不知道VBA。任何帮助?

回答

3
Sub MoveDownBasedOnColumnA() 

    Dim CurCell As Range 
    Set CurCell = ActiveCell 

    Dim CurCellInA As Range 
    Set CurCellInA = Me.Columns("A").Cells(CurCell.Row) 

    If IsEmpty(CurCellInA.Offset(1, 0).Value) Then 
    CurCell.EntireColumn.Cells(CurCellInA.End(xlDown).Row).Select 
    Else 
    CurCell.EntireColumn.Cells(CurCellInA.Row + 1).Select 
    End If 

End Sub 
+0

抛出“无效使用‘我’关键字” ......但我摆脱了“我“。现在它工作! 非常感谢! – dmd 2010-11-02 17:50:43

+0

@dmd:这是因为你把它放在一个模块中,而我的意思是它在工作表中,其中'Me'表示代码所在的表单。没有'Me'表示“在活动表单上”,它可能是你想要的东西。 – GSerg 2010-11-02 20:25:44

1
Sub a() 
    i = ActiveCell.Row 
    ret = i 
    j = ActiveCell.Column 
    While (Cells(i, 1).Value = "" And i < 16000) 
    i = i + 1 
    Wend 
    If (i = 16000) Then i = ret 
    Application.Goto Reference:=Cells(i, j) 
End Sub 

控制的“失控”的时候,你是波纹管的A列中使用的细胞限制