VBA 将光标向下移动到在 A 列中有值的下一行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4080287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:15:20  来源:igfitidea点击:

VBA to move cursor down to next row that has a value in column A?

excelexcel-vbavba

提问by Daniel

Column A has values in some rows, blank in others.

A 列在某些行中有值,在其他行中为空白。

I'm in some othercolumn. In the row I am in, column A is blank.

我在其他专栏。在我所在的行中,A 列是空白的。

I would like a macro which will move my cursor down - remaining in the current column - until it is on a row where column A is notblank.

我想要一个宏,它将向下移动我的光标 - 保留在当前列中 - 直到它位于 A 列不为空的行上。

This seems easy, but I know no VBA. Any help?

这看起来很容易,但我不知道 VBA。有什么帮助吗?

回答by GSerg

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

回答by Dr. belisarius

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   

Controlled "runaway" when you are bellow the column A used cells limit

当您低于 A 列使用的单元格限制时,控制“失控”