Sunday, April 2, 2017

Object Variable

'Object variable not set (Error 91)
'
'There are two steps to creating an object variable. First you must declare the object variable. Then you must assign a valid reference to the object variable using the Set statement. Similarly, a With...End With block must be initialized by executing the With statement entry point. This error has the following causes and solutions:
'
'
'You attempted to use an object variable that isn't yet referencing a valid object.
'Specify or respecify a reference for the object variable. For example, if the Set statement is omitted in the following code, an error would be generated on the reference to
'

Option Explicit
Sub test_objectvariable()

Dim testname As Range
Set testname = Range("a7", Range("a7").Offset.End(xlDown).Offset.End(xlToRight))

testname.Font.Color = rgbBlue
Range("a7", Range("a7").Offset.End(xlDown).Offset.End(xlToRight)).Select
testname.Interior.Color = vbRed
testname.Interior.ColorIndex = 23
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...