Is there a way to change the code below to select a range of named cells instead of a range of cells to accomplish the same thing?
I have 2 workbooks, one estimate.xlsm and one database.xlsm. On the estimate workbook, I have a customUI toolbar menu (each menu item points to the appropriate macro within database.xlsm) with options the estimator can select from to generate a quote based on common items that get quoted together. In the example code above, if the user selects 1 1/2 EMT Steel RT from the menu (in the estimate workbook), it will copy the range of cells from the database LIST worksheet, over to the estimate worksheet. The problem with the above, if items are needed to be added to the database, I have to adjust a lot of the code in the VBA, which makes it very time consuming.
I am wondering if I can select the same range of cells in the database and name them to pull from instead? For example, the range of cells would instead be named something like 1_1_2_EMTS_RT. This way, it would seem that it may not matter where I add items in the database as long as the names are updated appropriately. It sure would save a ton of time doing it this way.
Of note, there are no formulas on either worksheet in both workbooks, as the formulas used are contained within the VBA and added when a menu item is added.
Any other suggested improvements would be greatly appreciated.
Here's a mini-sheet of the estimate that shows how the items in the above example is copied to it when selected from the menu. In this example, the estimator will put in the quantity (in feet) for the EMT in cell B4, with cells B5, B8, and B9 containing a formula from the macro that will calculate the appropriate quantity needed. The other two cells vary, so the estimator will input the quantity manually.
VBA Code:
Sub EMTS_RT_1_1l2(control As IRibbonControl)
'
' EMTS_RT_1-1/2 Macro
'
Windows("DATABASE.XLSM").Activate
' EMT COUP CONN EL support label
Range("A8:G8,A30:G30,A74:G74,A108:G108,A702:G702,A715:G715").Select
Selection.COPY
Application.Run "BACK"
' extension formulas
ActiveCell.Offset(0, 0).Range("a1:G1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "=+RC[-2]*RC[-1]"
Selection.COPY
ActiveCell.Offset(1, 0).Range("A1:A5").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 2).Select
ActiveCell.FormulaR1C1 = "=+RC[-4]*RC[-1]"
Selection.COPY
ActiveCell.Offset(1, 0).Range("A1:A5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
' qty formulas
ActiveCell.Offset(0, -4).Select
ActiveCell.FormulaR1C1 = "=+R[-1]c*0.1"
ActiveCell.Offset(3, 0).Select
ActiveCell.FormulaR1C1 = "=@round((+R[-4]C/8),0)"
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=@round((+R[-5]C/25),0)"
ActiveCell.Offset(1, -1).Select
End Sub
I have 2 workbooks, one estimate.xlsm and one database.xlsm. On the estimate workbook, I have a customUI toolbar menu (each menu item points to the appropriate macro within database.xlsm) with options the estimator can select from to generate a quote based on common items that get quoted together. In the example code above, if the user selects 1 1/2 EMT Steel RT from the menu (in the estimate workbook), it will copy the range of cells from the database LIST worksheet, over to the estimate worksheet. The problem with the above, if items are needed to be added to the database, I have to adjust a lot of the code in the VBA, which makes it very time consuming.
I am wondering if I can select the same range of cells in the database and name them to pull from instead? For example, the range of cells would instead be named something like 1_1_2_EMTS_RT. This way, it would seem that it may not matter where I add items in the database as long as the names are updated appropriately. It sure would save a ton of time doing it this way.
Of note, there are no formulas on either worksheet in both workbooks, as the formulas used are contained within the VBA and added when a menu item is added.
Any other suggested improvements would be greatly appreciated.
Here's a mini-sheet of the estimate that shows how the items in the above example is copied to it when selected from the menu. In this example, the estimator will put in the quantity (in feet) for the EMT in cell B4, with cells B5, B8, and B9 containing a formula from the macro that will calculate the appropriate quantity needed. The other two cells vary, so the estimator will input the quantity manually.
BLANK ESTIMATE.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
3 | Conduit | Qty. | Material | Extension | Labor | Extension | SORT CODE | ||
4 | 1 1/2" EMT | 1,000 | 4.493 | 4,493.20 | 0.054 | 54.00 | 5 | ||
5 | 1 1/2" EMT STL. COUP R.T. | 100 | 4.7603 | 476.03 | - | - | 25 | ||
6 | 1 1/2" EMT STL. CONN R.T. | - | 5.6446 | - | - | - | 65 | ||
7 | 1 1/2" EMT 90 | - | 22.954 | - | 0.800 | - | 95 | ||
8 | 1 1/2" SUPPORT | 125 | 2.100 | 262.50 | - | - | 634 | ||
9 | 1 1/2" LABEL | 40 | 0.250 | 10.00 | 0.020 | 0.80 | 646 | ||
10 | - | - | - | - | - | ||||
BASE |