ErikJan wrote:Could I then call it like T R
if I have used Set for R
Yes, that is correct. Or, alternatively,
Call T(R)
The basic rule is: don't use Set for variables of a "simple" data type such as String, Long, Date or Boolean:
Dim strName As String
strName = "Erik Jan"
Do use Set for variables that refer to an object with properties, methods and/or events:
Dim wshData As Worksheet
Set wshData = Worksheets("My Data")
The following may seem confusing:
Dim strName As String
strName = Range("A1")
A Range is an object, with properties such as Font and Locked, and methods such as Copy and ClearContents. But when we try to assign a range to a String variable, VBA will automatically assign the Value of that range to the String variable. Value is the so-called default property of a Range object. The line
strName = Range("A1")
is actually shorthand for
strName = Range("A1").Value
When I use
Dim rngCell As Range
Set rngCell = Range("A1")
the declaration of rngCell as a Range and the use of Set make it clear to VBA that you don't want to assign the value of the cell to rngCell, but the cell object with all its properties.