TopLearner
Board Regular
- Joined
- Feb 25, 2022
- Messages
- 57
- Office Version
- 365
- Platform
- Windows
Good afternoon there,
I am pretty new to VBA and I am struggling to understand some certain concepts even I have been watching a few videos.
According to the definition of set: “Set”, is a keyword used in VBA programming to assign a reference to an object or cell range which is going to remain fix throughout the program or code in Excel. VBA Set basically helps us in avoiding repetitive input of range we need to select while executing the code. In excel, “Set” is mostly applied on worksheets/cell range in a particular sheet”.
For instance,
However, I do not understand why other times we do not have to use “set”
Why in this case I do not write?
Set sheet_count = Range("A1:A7").Rows.Count
From my first Sub ( SetRnge), could I also write:
Set Rnge = Range (“A2:A11”). Select?
Thanks
Sanchez
I am pretty new to VBA and I am struggling to understand some certain concepts even I have been watching a few videos.
According to the definition of set: “Set”, is a keyword used in VBA programming to assign a reference to an object or cell range which is going to remain fix throughout the program or code in Excel. VBA Set basically helps us in avoiding repetitive input of range we need to select while executing the code. In excel, “Set” is mostly applied on worksheets/cell range in a particular sheet”.
For instance,
VBA Code:
Sub SetRnge
Dim Rnge As Range
Set Rnge = Range (“A2:A11”)
Rnge.Select
End Sub
However, I do not understand why other times we do not have to use “set”
VBA Code:
Sub AddMultipleSheet2()
Dim sheets_count As Integer
Dim sheet_name As String
Dim i As Integer
sheet_count = Range("A1:A7").Rows.Count
For i = 1 To sheet_count
sheet_name = Sheets("mySheet").Range("A1:A10").Cells(i, 1).Value
If SheetCheck(sheet_name) = False And sheet_name <> "" Then
Worksheets.Add().Name = sheet_name
End If
Next i
End Sub
Why in this case I do not write?
Set sheet_count = Range("A1:A7").Rows.Count
From my first Sub ( SetRnge), could I also write:
Set Rnge = Range (“A2:A11”). Select?
Thanks
Sanchez