Con este software podemos elegir varias celdas para hacer correcciones de manera. Una referencia relativa es cuando Excel puede modificar libremente. How to Use Macros in Excel. This wikiHow teaches you how to enable, create, run, and save macros in Microsoft Excel. Macros are miniature programs which allow you to perform complex tasks, such as calculating formulas or creating charts.
Symptoms
Consider the following scenario.
You select a cell in a worksheet in Microsoft Excel 2000 or in a later version of Excel.
You use Microsoft Visual Basic for Applications (VBA) to create a formula-based conditional formatting program.
You use relative cell references in the VBA conditional formatting program.
You apply the conditional formatting to a cell other than the selected cell.
When you apply the conditional formatting, you notice that the conditional formatting is not set correctly.
For example, you experience this problem when you use a program that includes VBA code in an Excel worksheet that is similar to the following code:
This code automatically applies the conditional formatting to cell B1 when you enter '1' in cell A1. When you enter '1' in cell A1, you expect the color of cell B1 to change to red. However, the color of the cell does not change. The color of cell B1 changes to red only if you enter '1' in cell B1.
Additionally, the Conditional Formatting dialog box displays the formula as =B1=1 instead of =A1=1.
Workaround
To work around this issue, use one of the following methods.
Method 1: Use absolute cell references
You can use absolute cell references to refer to the cell that contains the formula instead of to refer to relative cell references.
For example, you can modify the Formula1:='=A1=1' text entry in the VBA code that is described in the 'Symptoms' section as Formula1:='=$A$1=1' to make the code use absolute cell references. This modified version of the VBA code is as follows:
Method 2: Select the cell that you want to use for conditional formatting before you apply the formula
When you want to apply conditional formatting to a cell, first select the cell that you want to use for the conditional formatting. Then, select the cell that you want to use for the formula. After you select this cell, modify the formula to suit your requirements.
To do this, follow these steps, as appropriate for the version of Excel that you are running.
Microsoft Office Excel 2007
Start Excel, and then open a new Excel worksheet.
In the Excel worksheet, select cell B1.
Click the Home tab.
Click Conditional Formatting in the Styles group, and then click New Rule.
Click Use a formula to determine which cells to format under Select a Rule Type.
Click inside the Format values where this formula is true box. Then, select the cell that you want to use for the conditional formatting.
Modify the value in step 6 to be =$A$1=1.
Click Format.
In the Format Cells dialog box, click the Fill tab.
Click the color 'red,' and then click OK.
In the New Formatting Rule dialog box, click OK.
In cell A1, type 1, and then press ENTER.
Verify that the color of the cell B1 changed to red.
Close the Excel worksheet.
Microsoft Office Excel 2003 and earlier versions of Excel
Start Excel, and then open a new Excel worksheet.
In the Excel worksheet, select cell B1.
On the Format menu, click Conditional Formatting.
Under Condition 1, click Formula Is in the list.
Click inside the data entry box. Then, select the cell that you want to use for the conditional formatting.
Modify the value in the data entry box to be =$A$1=1, and then click OK.
Click Format.
In the Format Cells dialog box, click the Patterns tab.
Select the color 'red,' and then click OK.
In the Conditional Formatting dialog box, click OK.
In cell A1, type 1, and then press ENTER.
Verify that the color of the cell B1 changed to red.
Close the Excel worksheet.
-->
Es más sencillo identificar los rangos por nombre que por la notación A1.Ranges are easier to identify by name than by A1 notation.Para asignar un nombre a un rango seleccionado, haga clic en el cuadro de nombre situado a la izquierda de la barra de fórmulas, escriba un nombre y, a continuación, presione la tecla ENTRAR.To name a selected range, click the name box at the left end of the formula bar, type a name, and then press ENTER.
Nota hay dos tipos de rangos con nombre: rango con nombre del libro y rango con nombre de hoja de cálculo específica.Note There are two types of named ranges: Workbook Named Range and WorkSHEET Specific Named Range.
Rango con nombre del libroWorkbook Named Range
Un rango con nombre del libro hace referencia a un rango determinado de cualquier parte del libro (se aplica globalmente).A Workbook Named Range references a specific range from anywhere in the workbook (it applies globally).
Cómo crear un rango con nombre del libro:How to Create a Workbook Named Range:
Como se ha explicado anteriormente, normalmente se creará escribiendo el nombre en el cuadro de nombre en el extremo izquierdo de la barra de fórmulas.As explained above, it is usually created entering the name into the name box to the left end of the formula bar.Tenga en cuenta que no se permiten espacios en el nombre.Note that no spaces are allowed in the name.
Rango con nombre específico de hoja de cálculoWorkSHEET Specific Named Range
Un rango con nombre de hoja de cálculo específica hace referencia a un rango de una hoja de cálculo específica y no es global para todas las hojas de cálculo en un libro.A WorkSHEET Specific Named Range refers to a range in a specific worksheet, and it is not global to all worksheets within a workbook.Puede hacer referencia a este rango con nombre solo con el nombre en la misma hoja de cálculo, pero desde otra hoja de cálculo debe usar el nombre de la hoja de cálculo incluyendo '!' en el nombre del rango (por ejemplo: el intervalo 'Nombre' '= Hoja1!Nombre').You can refer to this named range by just the name in the same worksheet, but from another worksheet you must use the worksheet name including '!' the name of the range (example: the range 'Name' '=Sheet1!Name').
La ventaja es que puede usar código de VBA para generar hojas nuevas con los mismos nombres para los mismos intervalos en esas hojas sin recibir un error que indica que el nombre ya existe.The benefit is that you can use VBA code to generate new sheets with the same names for the same ranges within those sheets without getting an error saying that the name is already taken.
Cómo crear un rango con nombre de hoja de cálculo específica:How to Create a WorkSHEET Specific Named Range: Iomega predator driver for mac.
Seleccione el rango que al que quiere dar nombre.Select the range you want to name.
Haga clic en la pestaña 'Fórmulas' de la cinta de opciones de Excel en la parte superior de la ventana.Click on the 'Formulas' tab on the Excel Ribbon at the top of the window.
Haga clic en el botón 'Definir nombre' en la pestaña Fórmula.Click 'Define Name' button in the Formula tab.
En el cuadro de diálogo 'Nombre nuevo', en el campo 'Ámbito', elija la hoja de cálculo concreta en la que se encuentra el rango que desea definir (por ejemplo, 'Hoja1'), esto hace que el nombre sea específico para esta hoja de cálculo.In the 'New Name' dialogue box, under the field 'Scope' choose the specific worksheet that the range you want to define is located (i.e. 'Sheet1')- This makes the name specific to this worksheet.Si elige 'Libro', será un nombre de libro).If you choose 'Workbook' then it will be a WorkBOOK name).
Ejemplo de rango con nombre de hoja de cálculo específica: el rango seleccionado para nombrar es A1:A10Example, of WorkSHEET Specific Named Range: Selected range to name are A1:A10
El nombre seleccionado del intervalo es 'nombre'. Desde la misma hoja de cálculo, se hace referencia al nombre denominado solo escribiendo en una celda '=nombre'. Desde otra hoja de cálculo, se hace referencia al rango de la hoja de cálculo específica incluyendo el nombre de la hoja de cálculo en una celda '= Hoja1!nombre'.Chosen name of range is 'name' within the same worksheet refer to the named name mere by entering the following in a cell '=name', from a different worksheet refer to the worksheet specific range by included the worksheet name in a cell '=Sheet1!name'.
Hacer referencia a un rango con nombreReferring to a Named Range
El siguiente ejemplo hace referencia al rango denominado 'MyRange' en el libro 'MyBook.xls'.The following example refers to the range named 'MyRange' in the workbook named 'MyBook.xls.'
El siguiente ejemplo hace referencia al rango de hojas de cálculo específico denominado 'Sheet1!Sales' en el libro 'MyBook.xls'.The following example refers to the worksheet-specific range named 'Sheet1!Sales' in the workbook named 'Report.xls.'
Para seleccionar un rango con nombre utilice el método GoTo, que activa el libro y la hoja de cálculo y, después, selecciona el rango.To select a named range, use the GoTo method, which activates the workbook and the worksheet and then selects the range.
El siguiente ejemplo muestra cómo se escribiría el mismo procedimiento para el libro activo.The following example shows how the same procedure would be written for the active workbook.
Código de ejemplo proporcionado por: Dennis Wallentin, VSTO & .NET & ExcelSample code provided by: Dennis Wallentin, VSTO & .NET & Excel
En este ejemplo se usa un rango con nombre como la fórmula de validación de datos.This example uses a named range as the formula for data validation.En este ejemplo se requiere que la validación de datos sea en la Hoja 2 en el rango A2:A100.This example requires the validation data to be on Sheet 2 in the range A2:A100.Esta validación de datos se usa para validar los datos introducidos en la Hoja 1 en el rango D2:D10.This validation data is used to validate data entered on Sheet 1 in the range D2:D10.
Ejecutar un bucle en las celdas de un rango con nombreLooping Through Cells in a Named Range
El siguiente ejemplo ejecuta un bucle en cada una de las celdas de un rango con nombre usando un bucle For Each..Next.The following example loops through each cell in a named range by using a For Each..Next loop.Si el valor de cualquiera de las celdas del rango supera el valor de Limit, el color de la celda cambia a amarillo.If the value of any cell in the range exceeds the value of Limit, the cell color is changed to yellow.
Acerca del colaboradorAbout the Contributor
Dennis Wallentin es el autor de VSTO & .NET & Excel, un blog que se centra en soluciones de .NET Framework para Excel y Excel Services.Dennis Wallentin is the author of VSTO & .NET & Excel, a blog that focuses on .NET Framework solutions for Excel and Excel Services.Dennis lleva más de veinte años desarrollando soluciones de Excel y es, además, coautor de 'Professional Excel Development: The Definitive Guide to Developing Applications Using Microsoft Excel, VBA and .NET (2nd Edition)'.Dennis has been developing Excel solutions for over 20 years and is also the coauthor of 'Professional Excel Development: The Definitive Guide to Developing Applications Using Microsoft Excel, VBA and .NET (2nd Edition).'
Soporte técnico y comentariosSupport and feedback
¿Tiene preguntas o comentarios sobre VBA para Office o esta documentación?Have questions or feedback about Office VBA or this documentation?Vea Soporte técnico y comentarios sobre VBA para Office para obtener ayuda sobre las formas en las que puede recibir soporte técnico y enviar comentarios.Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.