vba 确定哪个单元格处于活动状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22717399/
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-12 02:33:38  来源:igfitidea点击:

Determine which cell is active

excelvba

提问by Lou

I want to allow the user to click a button to copy information from column A, enter it in an IBM Personal Communications emulator, then, when they fill out that row of the data, press the button again to go back to column A and down to the next row.

我想让用户单击一个按钮从 A 列复制信息,将其输入 IBM Personal Communications 模拟器,然后,当他们填写该行数据时,再次按下该按钮返回到 A 列并向下到下一行。

This is what I have so far:

这是我到目前为止:

Option Explicit
Sub NextClaim_Click()
  Dim IDNum As String, Row
  Dim Emulator As Object

  ' Setting up the IBM Personal Communications emulator
  Set Emulator = CreateObject("pcomm.auteclsession")
  Emulator.SetConnectionByName ("A")

  ' Initial row that user starts macro on
  Row = ActiveCell.Row

  ' Get info from first row in column A (ex. A2)
  IDNum = Range("A" & Row).Value
  ' Pull up info in IBM Personal Communications emulator
  Emulator.auteclps.SendKeys "ret,i" & IDNum & ",m", 2, 2
  Emulator.auteclps.SendKeys "[enter]"

  ' If the last active cell that the user entered data in
  ' is not the the current row in column A (ex. A2), then
  ' add 1 to Row and go to the next row in column A (ex. A3)
  If ActiveCell.Range("A" & Row) = False Then
    Row = Row + 1
    Range("A" & Row).Activate
  End If

End Sub

I don't want the macro to go to the next row if the active cell is in column A when the button is pushed.

如果按下按钮时活动单元格在 A 列中,我不希望宏转到下一行。

回答by Gary's Student

How about:

怎么样:

Sub Lou()
    If ActiveCell.Column <> 1 Then
        ActiveCell.Offset(1, 0).Select
    End If
End Sub

EDIT#1

编辑#1

If you want to go to column Aas well as go down a row, then:

如果您想转到A列并向下一行,则:

Sub Lou()
    If ActiveCell.Column <> 1 Then
        ActiveCell.Offset(1, 0).EntireRow.Cells(1).Select
    End If
End Sub

回答by BrainO2

To determine which cell is active you can call the

要确定哪个单元格处于活动状态,您可以调用

ActiveCell.Row

Activecell.Column

ActiveCell.worksheet

methods that will return integers, with those you can programatically locate the active cell.

将返回整数的方法,您可以通过编程方式定位活动单元格。