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

时间:2014-03-28 15:45:11

标签: excel vba

我想允许用户单击按钮从A列复制信息,在IBM Personal Communications仿真器中输入,然后,当他们填写该行数据时,再次按下按钮返回列A和下一行。

这是我到目前为止所做的:

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

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

2 个答案:

答案 0 :(得分:2)

怎么样:

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

修改#1

如果您想要转到 A 列并连续下去,那么:

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

答案 1 :(得分:0)

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

ActiveCell.Row

Activecell.Column

ActiveCell.worksheet

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