Macro to run relative to current selected cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a macro to run relative to the current selected cell so that, if I
click the macro button the (eg.) whole current row will be selected along
with the four below, etc. - and not the the specific row from which I started
recording the macro.

Can anyone suggest a way?
Is there a code that refers to the current position?

Many thanks,
Mary
 
Sub selectrngfromactivecell()
ActiveCell.Resize(4, 1).EntireRow.Select
End Sub
or
Sub srfac()
Rows(ActiveCell.Row).Resize(4).Select
End Sub
 
One way:

Option Explicit
Sub testme()
ActiveCell.Resize(5, 1).EntireRow.Select
'do you want to go to column A of that first row?
'ActiveCell.EntireRow.Cells(1).Activate
End Sub
 
Simply using your arrow keys to navigate and pressing ctrl-c while recording
will select a relative range provided the relative reference button is
selected. On executing the macro it will select the range relative to where
your cursor is at that time. I have not, however, found a way to take it a
step further and name such a range relatively.
 

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

Back
Top