You are here:

Excel/Write a link to the next sheet

Advertisement


Question
Tom,
Sorry to pester you twice in one day.  I am trying to replace the VBA below to something quicker and without using Paste Link.  One challenge is the sheets do not have constant names or numbers.

'Update Run History
   'Select Previous Run Sheet
       ActiveSheet.Next.Select
   'Copy from Previous Run Sheet
       Range("A502:CA502").Copy
   'Select Newest Run
       ActiveSheet.Previous.Select
   'Paste Link on Newest Run Sheet
       Range("A65536").End(xlUp).Select
       ActiveSheet.Paste Link:=True
   'Copy Current Run Data Row
       Range("A502:CA502").Copy
   'Paste Link For Current Run Data
       Range("A65536").End(xlUp).Offset(1, 0).Select
       ActiveSheet.Paste Link:=True

I guess the new code would look something like this but obviously the second half is not going to work:
Range("A65536").End(xlUp).Formula = "=ActiveSheet.Next.Range("A502:CA502")"

Thanks again for all your help!

Answer
Ian,

If I read you code, on the first activesheet, you find the last cell with data in column A and then overwrite that cell and anything in that row with a link to the next sheet
then you dropdown one row and write a formula to link to the cell above.  So you end up with two identical rows (but with different formulas.  The code below does that.   Test it on a copy of your workbook and see if that is what you want.  

NOTE:  It assumes the next sheet does not have a space in the name.  


Sub abc()
Dim sh As Worksheet
Dim sh1 As Worksheet
Dim r As Range
Set sh = ActiveSheet
Set sh1 = ActiveSheet.Next
Set r = sh.Cells(sh.Rows.Count, 1).End(xlUp)
r.Resize(1, 79).Formula = "=" & sh1.Name & "!A$502"
r.Offset(1, 0).Resize(1, 79).Formula = "=" & r.Address(1, 0)
End Sub

--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.