Question : How do I define a name using VBA that accomplishes the same as Insert|Name|Define

I have many individual Excel cells that are referenced by other sheets (and other workbooks as well) so I want to define them all using VBA.  As new data come in each month I can just attach this macro, then other sheets will not have to change if source data cells change in macro only.

The following code is not doing it for me.
Code Snippet:
1:
2:
3:
4:
5:
6:
Sub DefineIt()
 
ActiveSheet.Range("F8").Name = "Balance"
   Balance= Balance.Value
 
End Sub

Answer : How do I define a name using VBA that accomplishes the same as Insert|Name|Define

Placing a macro in the Personal Macro Workbook allows that macro to be available to all opened workbooks. Macros can be added to the Personal Macro Workbook in one of two ways: using the macro recorder or manually placing the macro into Personal.xls.

To record a macro into the Personal Macro Workbook, choose the menu command Tools->Macro->Record New Macro. Enter a name for the new macro and select "Personal Macro Workbook" from the dropdown list. Click OK to being recording. To stop recording click the solid blue square on the macro recorder toolbar that is displayed while the macro is being recorded.

To manually place a macro into Personal.xls, press ALT+F11 to open the VBE, press CTRL+R to open the VBE project explorer, and look for a project named Personal.xls (see below for what to do if Personal.xls is not listed.) Open the project and either open an existing general module or add a new general module by choosing the menu command Insert->Module. Place the macro in the document window that appears. Press ALT-F11 to return to Excel.

If Personal.xls is not present then take any existing workbook, rename it to Personal.xls, and move it to the XLStart folder. The XLStart folder is located in:

   C:\Documents and Settings\Your Name\Application Data\Microsoft\Excel\XLStart

Note that if the Personal Macro Workbook does not exist when recording a macro to it Excel will create a new one.

Kevin
Random Solutions  
 
programming4us programming4us