To retrieve the value of the first cell in the Workbook level name Header2 try: Names('Header2').RefersToRange.Cells(1,1).value. Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback. Again- since this is Excel there are various ways to refer to ranges by names but the most flexible is to use the RefersToRange property of the Name object. Worksheets("Sheet1").Cells(counter, 3).Value = counter * 5 The variable counter is used as the row index for the Cells property. The following example fills the first 20 cells in the third column with values between 5 and 100, incremented by 5. To loop through a range of cells, use a variable with the Cells property in a loop. To do that, on the Developer tab, click Use Relative References, and then click Record Macro. With Relative referencing, the referred cells automatically adjust themselves in the formula as per your movement, either to the right, left, upward or downwards. Note You can record macros that use the Offset property to specify relative references instead of absolute references. So, if we type B1+B2 into the cell B3 and then drag or copy-paste the same formula into the cell C3, a relative reference would automatically adjust the formula to C1+C2. Sub Underline()ĪctiveCell.Offset(1, 3).Font.Underline = xlDouble In the following example, the contents of the cell that is one row down and three columns over from the active cell on the active worksheet are formatted as double-underlined. A common way to work with a cell relative to another cell is to use the Offset property.
0 Comments
Leave a Reply. |