ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Make active cell a variable, return there later (https://www.excelbanter.com/excel-programming/403708-make-active-cell-variable-return-there-later.html)

Andyjim

Make active cell a variable, return there later
 
User selects a cell and then hits a hot key to run a macro. I need the macro
to note that cell range, do some manipulations, then return to that cell and
run some offset copy/pastes from there. The offset part works fine, but in
the process of the first manipulations we're failing to return to the
original cell to then run the offsets from there. I figure if I set a
variable for the original cell, then I can return to that cell after the
first manipulations. But I don't know how to set a variable for the active
cell range, and don't know how to later return to (activate/select) the range
of the variable.

Per Jessen

Make active cell a variable, return there later
 

"Andyjim" skrev i en meddelelse
...
User selects a cell and then hits a hot key to run a macro. I need the
macro
to note that cell range, do some manipulations, then return to that cell
and
run some offset copy/pastes from there. The offset part works fine, but in
the process of the first manipulations we're failing to return to the
original cell to then run the offsets from there. I figure if I set a
variable for the original cell, then I can return to that cell after the
first manipulations. But I don't know how to set a variable for the active
cell range, and don't know how to later return to (activate/select) the
range
of the variable.


Hi

dim Target as string
Target=activecell.address
'your code
range(target).select

//Per



JLGWhiz

Make active cell a variable, return there later
 
x = ActiveCell.Address gets the variable loaded for the original cell.
Range(x).Offset(0, 1) is one column to the right of the original cell.
Range(x).Offset(-1, 0) is one row above the original cell, unless the
original cell was on row 1, in which case you get an out or range error.
etc.
If you are using the select and activate style of code writing then
Range(x).Activate will take you to the original cell.

"Andyjim" wrote:

User selects a cell and then hits a hot key to run a macro. I need the macro
to note that cell range, do some manipulations, then return to that cell and
run some offset copy/pastes from there. The offset part works fine, but in
the process of the first manipulations we're failing to return to the
original cell to then run the offsets from there. I figure if I set a
variable for the original cell, then I can return to that cell after the
first manipulations. But I don't know how to set a variable for the active
cell range, and don't know how to later return to (activate/select) the range
of the variable.


FSt1

Make active cell a variable, return there later
 
hi
another way to do it;

Dim r as range
set r = activecell
run code here
r.select

to do stuff on another sheet then return to the previous sheet cell:
dim r as range
dim s a worksheet
select another sheet to run code.
s.activate
r.select

regards
FSt1

"Andyjim" wrote:

User selects a cell and then hits a hot key to run a macro. I need the macro
to note that cell range, do some manipulations, then return to that cell and
run some offset copy/pastes from there. The offset part works fine, but in
the process of the first manipulations we're failing to return to the
original cell to then run the offsets from there. I figure if I set a
variable for the original cell, then I can return to that cell after the
first manipulations. But I don't know how to set a variable for the active
cell range, and don't know how to later return to (activate/select) the range
of the variable.



All times are GMT +1. The time now is 09:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com