Move active cell through current selection

  • Thread starter Thread starter Mike King
  • Start date Start date
M

Mike King

Is there a way to move the active cell through the current selection using
an external program? I'm trying to get a data capture program I have
written to update the active worksheet's cells. I would like the user to
select the cells to be updated, then my program will hopefully update the
active cell then move to the next cell in the selection the same way the tab
key does.

The following code shows my problem. The Goto method changes the selection
and doesn't do the same thing the tab key does.

' Get Excel instances
Set a = GetObject(, "Excel.Application")

' Set text of active cell
e.ActiveCell.Value = "Hello, World!"

e.Goto e.ActiveCell.Next
 
use a for each something like this...

Dim rng as Range
'Get Excel instances
Set a = GetObject(, "Excel.Application")

for each rng in a.Selection
rng.value = rng.address
next rng
 
Dim rng as Range
'Get Excel instances
Set a = GetObject(, "Excel.Application")

for each rng in a.Selection
rng.value = rng.address
next rng

Thank you for your help.

With this approach the active cell does not change.
 
With this approach the active cell does not change.

Your correct the active cell doesn't change but what the code does is loop
through each cell of the selected range and is no need to select the cell
(make it the active cell) to manipulate the data in it.

Mike
 
Mike H said:
Your correct the active cell doesn't change but what the code does is loop
through each cell of the selected range and is no need to select the cell
(make it the active cell) to manipulate the data in it.

I didn't explain why move the active cell is important to me.

I found my solution. I'm going to determine the next cell in the selection
using an IEnumVARIANT interface and set the active cell by calling the
Activate method.

Thanks for pointing me in the right direction.
 
Back
Top