Move active cell through current selection

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
 
J

Jim Thomlinson

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
 
M

Mike King

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.
 
M

Mike H

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
 
M

Mike King

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top