adjusting a recorded macro in edit mode

  • Thread starter Thread starter CJ
  • Start date Start date
C

CJ

In a recorded macro I make a cell active and I want it to select the active
cell and the 4 cells to the right of it and preform an action.

The macro works but only if it starts in the same cell each time. I want to
be able to click ANY cell and have the macro work I don't know how to adjust
the code. Its listing a range (E9:I9) I need ActiveCell and the four to the
right of it
How do you do this in code??
 
Then when I run the macro it will always select these same cells. This is my
problem if I am in cell H4 I want it to select H4 and the four cells next to
that and if i make S65 active I want s65 and the 4 cells on the right
Whatever cell I decide to make active I want it to select that one and the
4 cells on the rightthe below code limits me to only the range specified

ActiveCell.Range("A1:E1").Select
 
the below code limits me to only the range specified

No, it doesn't. It's relative (rather than absolute) referencing. I checked
it.

Run it as a single line sub from any cell. It selects the cell and its
4-to-the-right neighbours.

Rgds,
Andy
 
/Thanks I'm new to vba and thought it would limit me to just the range
stated
Thanks again Chris
 
No worries. If you're learning by using the recorder (which is fine) ...


.... when you start recording, the Recording toolbar should appear. If it
doesn't, turn it on via View >> Toolbars. It has two buttons. One is Stop
Recording. The other is a toggle between absolute and relative mode. Start
recording, then play around with selecting stuff, switching over, selecting
more stuff, switching back, etc. Afterwards, study the code to see how it
works.

Rgds,
Andy
 
Try using this code:

Start_Cell = ActiveCell.Address
Finish_Cell = ActiveCell.Offset(0, 4).Address
Range(Start_Cell, Finish_Cell).Select

Later

Michel Cinq-Mars
 
Back
Top