You are here:

Excel/moving cells and code


My worksheet is a work in process. I have decided that the layout of sections of cells would serve me better in a different place in the worksheet. There is a lot of VBA code directed at those cells so I can't just cut and paste like I would with cell formulas. Is there a way to move sections of cells and update the code to match the new location?


the answer is no.   VBA is an addon to Excel and it not integrated into its internal ability to adjust formulas as changed are made to the worksheet.  

If you anticipate such a requirement, you can use named ranges in your code.  So instead of

worksheets("Sheet1").Range("A1").value  + worksheets("Sheet2").Range("Z6").value

you could have named the A1 location   LOC1  and the Z6 location LOC2 using defined names.

then in your code you could do

   [LOC1] + [LOC2}

   Range("LOC1") + Range("LOC2")

and if you changed the cells with that name, the vba code would not need to be adjusted.

Sorry there isn't a better way.  Possibly using the Replace command in the VBE might be a start.  But no built in automatic way beyond what I have talked about.

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


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


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.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 All rights reserved.