ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get a macro to start in the right spot! (https://www.excelbanter.com/excel-programming/300102-how-get-macro-start-right-spot.html)

buzzled

How to get a macro to start in the right spot!
 
I have a few macros that I use to input predetermined numbers in cells.

ie:
Sub testmacro()
Range("A3").Select
ActiveCell.FormulaR1C1 = "25"
Range("A4").Select
ActiveCell.FormulaR1C1 = "10"
Range("A5").Select
ActiveCell.FormulaR1C1 = "2"
Range("A6").Select
ActiveCell.FormulaR1C1 = "4"
Range("A7").Select
End Sub

The problem is that if a row is inserted above A3 then I want the macr
to start at A4. In other words I want it to start in the same relativ
cell.

Thank

--
Message posted from http://www.ExcelForum.com


billyb[_4_]

How to get a macro to start in the right spot!
 
You could give a name to each of your target cell, and that name woul
remain with the cell wherever it goes as a result of insertions, etc.
You can name your ranges in Excel by doing InsertNameDefine, or yo
can simply select your target cell, type a range name in the Name bo
near the top left of the worksheet screen and (required) press Enter.

billy

--
Message posted from http://www.ExcelForum.com


buzzled[_2_]

How to get a macro to start in the right spot!
 
Thank

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 04:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com