This is a quick and simple VBA code with some comments about the structure and how it the basic syntax works for beginners.

Credit to WiseOwlTutorials, you can check him out Youtube.

Sub createAndLabelNewSheet()

'create new worksheet // this is a comment. comment is denoted by an 'apostrosphe sign

'Basic VBA sentence structure
'thing.action
'always name and object or item which is the ''thing" and then follow it by a dot 'and then the action to be performed, which is the "action"
'the thing is referred to as "object" and the action is referred to as "method"
'the methods in VBA have little green icons on them.

Worksheets.Add

'add titles to cells
'to add titles or similar actions, the normal vba syntax is as follows
'object.Property = value
'which basically means that you change the property of the object. You change 'the property by assigning new values to it.
'we can use the "range" method to locate a cell
Range("A1").Value = "Created by"
Range("A2").Value = "Created on"
Range("A3").Value = "Version"

'add user values to cells
'environ function lets you get some windows environmental variables

Range("B1").Value = Environ("UserName")
Range("B2").Value = Date
Range("B3").Value = 1

'formatting the titles
Range("A1:A3").Font.Color = vbBlue
'Range("A1:A3").Interior.Color = rgbLightCyan
Range("A1:A3").Interior.Color = rgbRed

End Sub

 

This is the simple result of the above code.

vba-result-code

 

Similar Posts

One Comment

  1. I am not sure where you’re getting your info, but good topic.
    I needs to spend some time learning much more or understanding
    more. Thanks for magnificent information I was looking for this information for my mission.

Leave a Reply

Your email address will not be published. Required fields are marked *