Hello .i have create this code from scratch,watching a video in youtube.
My level is at the beginning and I am learning vba code and I am trying to learn to make simple codes.
The code I have create is this
Sub objectvariables()
Dim wb As Workbook
Dim ws As Worksheet
Dim box As Range
Set wb = Workbooks(1)
Set ws = Workbooks(1).Worksheets(1)
End Sub
Then I have simplified a little .i changed the workbooks(1) in wb because in the previous line the workbook has became in wb
Sub objectvariables()
Dim wb As Workbook
Dim ws As Worksheet
Dim box As Range
Set wb = Workbooks(1)
Set ws = wb.Worksheets(1)
End Sub
After I put the variable box in the code
Sub objectvariables()
Dim wb As Workbook
Dim ws As Worksheet
Dim box As Range
Set wb = Workbooks(1)
Set ws = wb.Worksheets(1)
Set box = Workbooks(1).Worksheets(1).Range("b2")
End Sub
After I made it even more simple
Sub objectvariables()
Dim wb As Workbook
Dim ws As Worksheet
Dim box As Range
Set wb = Workbooks(1)
Set ws = wb.Worksheets(1)
Set box = ws.Range("b2")
End Sub
Then the last code is this one here.
Sub objectvariables()
Dim wb As Workbook
Dim ws As Worksheet
Dim box As Range
Set wb = Workbooks(1)
Set ws = wb.Worksheets(1)
Set box = ws.Range("b2")
box.Value = 5
End Sub
Theoretically if I run this code in cell B2 should be the value of 5(at least according to the video) .
unfortunately when I am using this code nothing happens. there are no errors in syntax but nothing happens.
Am I missing anything?
Thank you in advance
Bookmarks