Sunday, April 2, 2017

cell Selection

'Selecting and Activating Cells
'
'When you work with Microsoft Excel, you usually select a cell or cells and then perform an action, such as formatting the cells or entering values in them. In Visual Basic, it is usually not necessary to select cells before modifying them.
'
'For example, if you want to enter a formula in cell D6 using Visual Basic, you do not need to select the range D6. You just need to return the Range object for that cell, and then set the Formula property to the formula you want, as shown in the following example.
'

Option Explicit

Sub TestSelectCells()

Range("a8").Select
ActiveCell.value = 11

Cells(8, 2).Select
ActiveCell.value = "vinay"

[d10].Select
ActiveCell.value = "New Way to refer cells"

End Sub

Sub Name_SelectedCells()

Range("Vendor").Font.Color = rgbBlue
[segment].Font.Color = rgbRed
Range("year").Font.Color = rgbGreen
[value].Font.Color = rgbDarkRed

'relative cell refernce
Range("L5").End(xlDown).Offset(1, 0).Select
ActiveCell.value = ActiveCell.Offset(-1, 0).value + 1
Range("i5", Range("i5").End(xlDown).End(xlToRight)).Interior.Color = rgbAliceBlue

'using current region
Range("a1").CurrentRegion.Select
Selection.Copy
Worksheets("Sheet6").Select
Range("a1").Select
Range("a1").PasteSpecial
Range("a1").PasteSpecial xlPasteColumnWidths

End Sub

No comments:

Post a Comment

*INTERVIEW QUESTIONS

* Ques 01. What is the difference between ByVal and ByRef and which is default ? Ans-  ByRef : If you pass an argument by reference when...