Relative reference and macros

  • Thread starter Thread starter Alan
  • Start date Start date
A

Alan

How do I say "go down one cell from where I am" in VBA code?

Thanks, Alan
 
One way:

Activecell.Offset(1, 0).Select

another

ActiveCell(2, 1).Select
 
What code would you use to go from one sheet to a named sheet and the
return to the original sheet (but without having to name the origina
sheet)
 
I would almost never "go to" another sheet. For example:

Sheets("Sheet2").Range("A1:J10").Copy Destination:= _
ActiveSheet.Range("B13")

copies from Sheet2 to the active sheet without ever changing the
selection. Using the range object directly makes your code smaller,
faster, and IMO, easier to maintain.

However, to do what you're asking:

Dim shOriginal As Worksheet
Set shOriginal = ActiveSheet
Sheets("Sheet2").Select

'Do whatever

shOriginal.Select
 

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