Lou
Lou

Reputation: 403

Determine which cell is active

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.

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.

Upvotes: 1

Views: 7406

Answers (2)

Gary's Student
Gary's Student

Reputation: 96753

How about:

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

EDIT#1

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

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

Upvotes: 2

BrainO2
BrainO2

Reputation: 1374

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.

Upvotes: 0

Related Questions