Hi i'm new in VBA can you please explain why my debug.print give error? Thank you
Sub Macro1()
Dim ws As Worksheet
i = Worksheets.Count
Set ws = Worksheets(i)
Debug.Print ws
End Sub
You can't print the worksheet object (ws). You can print some of it's properties e.g. it's name. Also, put Option Explicit at the top of your module and declare i.
You can use Debug.Print to write out information, to help with debugging, to the immediate window. The immediate window can be opened with Ctrl + G.
You can gain the same information by putting ? in the immediate window before the same code line e.g. ?ws.Name (provided your code has been halted during execution, example, with STOP keyword, and has retained the required value)
Option Explicit
Sub Macro1()
Dim ws As Worksheet
Dim i As Long
i = Worksheets.Count
Set ws = Worksheets(i)
Debug.Print ws.Name
End Sub
Debug.Print ws.Name