Showing posts with label Cells/Range. Show all posts
Showing posts with label Cells/Range. Show all posts

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

Thursday, March 16, 2017

How to Select Cells/ Range

Sub cells_selection()

Dim i As Integer
i = 5
Range("A1:D10").Select
Cells(5, 10).Select
Range("A" & i).Select
Cells(1, Columns.Count).Select
Range(Cells(1, 1), Cells(5, 5)).Select
Range(Range("A1:A5"), Range("H1:H5")).Select

End Sub

Wednesday, March 15, 2017

*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...